Jump to content
Orkun

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) {
	$stpage->save();
}

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 = '';

        if($page->is("template=specialities-clinics")){
        	   $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

            wire('pages')->setOutputFormatting(true);
            $content = $page->render($options);
            wire('pages')->setOutputFormatting(false);

            if($content){
            	$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:

wire('pages')->setOutputFormatting(true);
$content = $page->render($options);
wire('pages')->setOutputFormatting(false);

like this:

$page->setOutputFormatting(true);
$content = $page->render($options);
$page->setOutputFormatting(false);

 

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,
      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)?
      Thanks,
      Flo 
    • By snck
      Hello,
      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.
      Cheers,
      Flo

    • By fruid
      Hi,
      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,
      Fred
    • 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.
    • By flydev 👊🏻
      Bootstrap-4 Minimal site profile for ProcessWire
      This profile is based on the "minimal site profile (intermediate edition)" and bundled with Boostrap v4.4.1
       
        Features
      Bootstrap SASS Font-Awesome SASS Render / helper functions for : Simple ul navigation Bootstrap Multi-level navbar Bootstrap Carousel Bootstrap Cards Bootstrap Jumbotron Boostrap Accordion Assets minification, files bundle   Dependencies
      jQuery Popper.js Bootstrap FontAwesome   Prequisites
       You'll want to install the following on your system before proceeding:
      Yarn / NPM How To Install
      Download the zip file at Github or clone directly the repo with git clone and skip the step 2. Extract the folder site-pwbs4-master into a fresh ProcessWire installation root folder. During the installation of ProcessWire, choose the profile "ProcessWire Bootstrap 4 profile".   After installation
      You can find the development file (CSS/SCSS/JS) in site/assets/dev/src
      The profile can be used as is only with $config->debug set to false. To use it in debug mode, you are required to install the dependencies with the package manager.
      Open a terminal in site/assets/dev and execute the following command-line: yarn Available commands :
      Rebuild, minify and bundle assets for release : yarn build   References
      Bootstrap v4 documentation ProcessWire documentation ProcessWire Forum: bootstrap tag ProcessWire Forum: bootstrap related posts   Credits
      The ProcessWire staff Inspiration from @gebeer and his Bootstrap 3 profile post Members who contributed in various post about Bootstrap navigation and code (see code-source for refs). Screenshots

×
×
  • Create New...