Jump to content

Trying to save pages from root folder / Permission Problem

Recommended Posts

Hi Guys

I am trying to save Pages with the API from the root Folder in a file named refreshIndex.php. The code looks like this:

$root = "/path/to/root";
include($root . "index.php");

//$doctors = wire('pages')->find("template=doctors");
$jobs = wire('pages')->find("template=jobs");
//$news = wire('pages')->find("template=news");
//$specialities = wire('pages')->find("template=specialities-clinics");
//$events = wire('pages')->find("template=signup-form-formbuilder");
//$dbpages = wire('pages')->find("template=doctors|specialities-clinics|news|signup-form-formbuilder|jobs");

//$allpages = wire('pages')->get(27200)->find("");
foreach ($jobs as $stpage) {

Now at the moment I am trying to save Job Pages. They are 2 job pages right now. It saves 1 of them and at the 2 one I get an Error like this:

Error: Uncaught WirePermissionException: Page '/de/jobs/test-job_ge/' is not currently viewable. in /pathtoroot/wire/modules/PageRender.module:319

They are both using the same template with the same permissions respectively they are visible (guest user is viewable). And also the languages of the page are all active inside page settings.


Somehow my Hook is responsible for this. The hook is the reason for my Script above. I am trying to update the index field for my site search. The hooks works fine when I am saving the pages from the backend interface, but I can't save all pages from the backend since they are over 1500 pages I need to save.

$this->addHookBefore('Pages::saveReady', $this, 'hookIndexingBefore');

protected function hookIndexingBefore( HookEvent $event ) {
 		$options = array();
        $page = $event->arguments("page");

        // abort when true
        if(!$page->template->hasField("index")) return;
        if($page->isNew() || $page->isTrash()) return;

        // save user lang
        $language = $this->wire("user")->language;    

        // clear index field at the begin
        $page->index = '';

        	   $options['sender'] = $page->choose_sender_2016->id;
        $options['pagename'] = $page->name;

        foreach($this->wire("languages") as $lang) {

            $this->wire("user")->language = $lang; // change user lang

            $content = $page->render($options);

            	$startStr = "<!--### start-indexing-area ###-->";
		        $endStr = "<!--### end-indexing-area ###-->";
		        preg_match_all('/'.$startStr.'(.*)'.$endStr.'/siU', $content, $matches);
		        $newContent = preg_replace("/<div class='breadcrumb.*'>.*<\/div>/siU", '', $matches[1][0]);
		        $newContent = str_replace('<', ' <', $newContent);
		        $newContent = strip_tags($newContent);
		        $newContent = preg_replace("/\s\s+/", " ", $newContent);

            $page->index .= $newContent;

        $this->wire("user")->language = $language; // restore user language


Share this post

Link to post
Share on other sites

Ok Guys I could make it to work changing:

$content = $page->render($options);

like this:

$content = $page->render($options);


Share this post

Link to post
Share on other sites

EDIT: Ok it doesn't matter anymore. I removed the index field from overview-content-page and fetch-content-page template since I realised that they are just overview pages which can be searched through their title and body field. So no need for an index field.

I have now another really strange problem. When I try to change the template of a page to a specific template (in this case overview-content-page or fetch-content-page) I end up on a blank page with this url (/processwire/page/edit/saveTemplate) and the template doesn't get changed. It's because of my Hook for updating the index field. But I don't know what is actually causing this. Since I have also other templates with the field index in it and there are no problems.


Edited by Nukro

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By snck
      Hey there,
      for a client website I need to implement a "reviewer" role. "Reviewers" should be able to review new (unpublished) articles to give feedback to editors, but not have the permission to change them. 
      I built a new "reviewer" role that only has page-view permissions for the respective templates, but this permission does not include viewing unpublished pages. How can I grant them access to the unpublished articles without giving them page-edit permission?
    • By snck
      I want my editors to be able to use the page lister, especially the bookmarks. I added the page-lister permission to the editor role, but Page lister ("Find" menu item) does not show. Is there anything else I have to do? Links to bookmarks work for the editors, but I would be glad to show them the menu item as well.
      Maybe this has something to do with the long history of the site (started with ProcessWire 2.4 and upgraded to 3.0.148 over the years)?
    • By snck
      for a project I have pages with different “content areas“ that can be edited only by specific user roles. In the past I setup a fieldset (tab) containing all the fields that should be available to only one specific group of users and set the fields' view and edit permissions (in the Access tab) accordingly. The result was as expected: Users assigned to the specific role could see the tab, click on it, edit content, users without the role could not see the tab. After updating this installation to 3.0.148 yesterday I wanted to setup another tab following the same principle, but I have no "Access" tab for the fieldset to limit access to the specific role. I even tried cloning an existing (and still working) fieldset. The existing fieldset has some template overrides (screenshot attached) that lead to the desired behaviour, but I am not able to reproduce these settings because there is not "Access" tab for my fieldset in template context either.
      Is this a bug in 3.0.148? Has the fieldset fieldtype changed? Am I missing anything here?
      I am glad to hear from you guys.

    • By fruid
      this is the first time I'm using ProcessWire.
      I thought I get how fields, template and pages work, but when I create a template in the CMS, it doesn't generate any file in site/templates/
      Then I thought I might need to create a blank file myself manually on the FTP (which already seems odd to me).
      Once I did that, I tried to add fields to the template but again, doesn't write to the php file.
      When I create a new page and apply said template to it, the page stay blank.
      AFAIK the mod_rewrite of the apache is on and I went for the worst case scenario described here https://processwire.com/docs/security/file-permissions/ and set all file-permissions for future files to 0666 and folders to 0777 in the config.php
      What am I not getting and what am I doing wrong?
      Help is appreciated, stay save everybody,
    • By MarkE
      Having just wasted the best part of a day debugging an access issue because I hadn't realised that page-edit-created negated any related page-edit permissions, could I suggest that a note to this effect is included in the default title. I have amended the title on my system to read:
      Edit only pages user has created (IMPORTANT: This will negate any related page-edit permission - including permissions granted to a user by other roles) ..although it may be possible to make it briefer while not losing clarity and impact.
  • Create New...