blackeye1987 Posted January 8, 2015 Share Posted January 8, 2015 Hi, i got a weird problem and cannot find any answer. i have a module that creates pages when a certain template is set (posted it somewhere in the forum) and i have another module that if a page is saved it checks another page settings if the page is allowed to be published or unpublished. (this happens on page save and worked the last few weeks) now it seems like when the subpage gets created it is always unpublished. after saving it again, the original intended script works as programmed. so as you might know, i wonder if, there has been a change between creating a page and just saving / updating it. if there hasn't been any changes to this the problem might be somewhere else, but tbh i know that there is no other modules used / installed by me which are changing the status here. Link to comment Share on other sites More sharing options...
horst Posted January 8, 2015 Share Posted January 8, 2015 It would be god if you can provide some more details about the hooks you are using for those modules, (a few lines of code for each of both modules) And if you create pages via API you also have to save them, so what is the difference between saving them the fisrt time (via API after creation) and the second one? A few lines of code you use to create save them would be helpful too. Link to comment Share on other sites More sharing options...
blackeye1987 Posted January 8, 2015 Author Share Posted January 8, 2015 well the code is very specific and throws more questions then it could provide answers. but there you go: i create the pages with my child generater public function createChildren($event){ $page = $event->arguments[0]; $query = $this->db->query("SELECT * FROM ".strtolower($this->className).";"); //foreach child creater object foreach($query as $cco){ $t = $cco['parent_template']; $ct = $cco['child_template']; $cn = $cco['child_name']; $ci = (int) $cco['child_numbers']; $c = ''; //will be used as new Page if($t == $page->template->id){ if($ci > 0){ for($i=1;$i <= $ci;$i++){ $c = new Page(); $c->template = $ct; $c->parent = $page; // set the parent //if only 1 entry do not add the 1 if($ci == 1){ $c->name = $cn; // give it a name used in the url for the page $c->title = $cn; // give it a name used in the url for the page } else { $c->name = $cn.$i; // give it a name used in the url for the page $c->title = $cn.$i; // give it a name used in the url for the page } $c->title = $c->name; $c->tab_position = $i; $c->outputFormatting(false); $c->save(); } } } } } you have to configure it in processwire. basically. i set a template.when this template is set -> create x pages with template n if($page->template == 'tab'){ $parent = $page->parent('include=all,template=a_temp'); if($parent->id > 0){ if($parent->a_conf->id > 0){ foreach($parent->a_conf->b_affinity->b_conf->tab_add as $ta){ if( ($ta->tab_position == 5 && $page->tab_position == 1) || ($ta->tab_position == 6 && $page->tab_position == 2) ){ if($page->is(Page::statusUnpublished)){ $page->removeStatus(Page::statusUnpublished); $page->save(); } return; } } } if(!$page->is(Page::statusUnpublished)){ $page->status = Page::statusUnpublished; $page->setOutputFormatting(false); $page->save(); } return; } } return; this is where "the magic" happens. i have an institute(a) which has tabs. this institute(a) is a subinstitute of another institute(b). b is allowed to tell a if they can publish tab 5 and 6 of their institute.content from b is always provided b can only add content. the problem is:institute a gets created and linked with instutite binstitute b is already configured.so institute a gets its config basically preset.on creating institute a (no matter what config institute b has)tab 1 and 2 (on a side) are not publishedeven if institude b allows them to use them (institute b has them on tab 5 and 6)like i said.. i think this whole thing is more confusing then my starting question. Link to comment Share on other sites More sharing options...
blackeye1987 Posted January 8, 2015 Author Share Posted January 8, 2015 i found a possibility.. which has nothing to do with my code.. in some way.. if i know more i will tell you in this post.tab has a lower id in the child generator then the konfiguration, so there is an possibility that the tabs are getting created before the configuration so obviously the tab cannot find the config. 1 Link to comment Share on other sites More sharing options...
blackeye1987 Posted January 9, 2015 Author Share Posted January 9, 2015 well i found the problem... so as the child generater does everything right. i was looking on the wrong spot. the customer comes from a sso page linked to me. there i am creating on the fly his institute (A) if not already in the system. this is the what happens in order. 1 customer clicks link 2. customer sends data with his post to our sso login 3. creating the institute on the fly 4. child generater creates all subpages (2 tabs a configuration and some other stuff) 4.1 configuration gets created 4.2 tabs get created (the konfiguration at this point does not have the reference which the institute B is! so at this point the tabs get created without the correct info (due to my superb skillz i already cought it if no config or institute found make them unpublished) 5. configuration gets filled with the infos needed like who is my institute B 6. login i added between 5 and 6 1 step //find all due they might be unpublished foreach($b->find('template=tab,include=all') as $t){ $t->setOutputFormatting(false); $t->save(); } now everything works as intended. thanks for everyone who read my code and didn't told me i am a crazy scientist good day everyone Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now