-
Posts
349 -
Joined
-
Last visited
-
Days Won
4
Everything posted by da²
-
I'm not a PHP expert, I use this language since a few years but only intensively since last year. And I just found the spaceship operator <=>. A few days before I implemented an ArrayUtils::floatCompare() because I found bugs in my code where I compared floats like int, because usort callback function return value is an int and I was returning "$float1 - $float2"... followed by the implicit cast to int... not perfect sorting. ? I know I've already read about this 'spaceship.' I remember the name, but probably it wasn't the right time to fully understand its meaning. ^^ Did you know this operator? EDIT : thanks to the moderator who pinned this topic, I owe you a beer! ?
-
Why? I don't give names, I let PW create it from title.
-
Is it faster to add START TRANSACTION and COMMIT in the sql file? In my current project I sometimes import 5000 pages using PW API, and with transactions (wire()->database->beginTransaction(); wire()->database->commit();) it is done in 20-30 seconds.
-
Hi, If your page reference field can contain multiple pages, you should add pages like this: $page->sammelband_verweis->add($matchingPage); Also, for optimization, you should save the page outside of the loop: $of = $page->of(false); foreach ($page->children("include=hidden") as $child) { if (! empty($child->sammelband_text)){ // doing some sanitation to the field's content $SammlungTitel = extractTitleAfterYear($child->sammelband_text); $escapedTitle = $sanitizer->selectorValue($SammlungTitel); $matchingPages = $pages->find("template=publikation, include=hidden, title^=$escapedTitle"); if ($matchingPages->count() > 0) { $matchingPage = $matchingPages->first(); $page->sammelband_verweis->add($matchingPage); } } } $page->save('sammelband_verweis'); $page->of($of);
-
Page Autocomplete selector string within a repeater with dependencies
da² replied to Kiwi Chris's topic in General Support
I've reached the same conclusions when I tried with Profields Table. I use a lot the autocomplete field because the select is not good for hundred of pages. From what I understand, limitation is on both sides: the find() string selector, and the ProcessPageSearch. Just one needs to be improved to solve this limitation. The easier fix is probably ProcessPageSearch: we need a hookable method to replace results, like the getSelectablePages() of InputfieldPage, and like in other hooks we need the page and field from where the request was sent. -
Page Autocomplete selector string within a repeater with dependencies
da² replied to Kiwi Chris's topic in General Support
I had a look at it, I remember trying to do the same with an autocomplete field except I tried to reference pages from a Profields Table, and never found a correct solution. What you can do is search for repeater items instead of the pages inside items. Or hooking into ProcessPageSearch::findReady to update selector, but it's not clean, I think only solution is to add "id=xxx|xxx|xxx|xxx|xxx|xxx|...." in selector. ? Or maybe hooking into ProcessPageSearch::executeFor and doing your own search. For the hooks you need to know on what page you are, I don't know how. EDIT: Except with a ugly hack, like adding in selector string "name=page.id", and so in ProcessPageSearch::executeFor you can get the page id with $event->return, do a search directly in repeater (like this) and finally format and return results. -
Page Autocomplete selector string within a repeater with dependencies
da² replied to Kiwi Chris's topic in General Support
@Kiwi Chris Yes, page.vintage refers to the property vintage on the current page. I thought it was your goal, but I missed you are trying to reference item fields in repeater. If I understand good, in your page you have a page reference field with the selector string, and this field must reference the pages that are set in a repeater on the same page? Or is the page reference field inside the repeater too? ? -
Page Autocomplete selector string within a repeater with dependencies
da² replied to Kiwi Chris's topic in General Support
@Kiwi Chris Try this: productVintage.id=page.vintage.id or: productVintage=page.vintage If you search by title, it would be: productVintage.title=page.vintage.title But I don't see any reason to search by title instead of id. -
Best way to move a Processwire site to a new server 2020?
da² replied to modifiedcontent's topic in General Support
@BIMAQ-Admin Take care that this properties in the destination site/config.php are the same as the original site: $config->userAuthSalt = 'xxx'; $config->tableSalt = 'xxx'; The procedure could be more simple, no need to install PW then delete the database. Just rsync the files between 2 servers (with some exclusions for sessions and cache), and use mysql_dump to copy database from old server to new one. This is how I replicate my dev environment to the staging server, except I also exclude site/config.php after it was initially uploaded and adapted to server config. Example of database copy from source server to destination, to run on source server: mysqldump --add-drop-database -uSQL_USER_SOURCE -pSQL_PASSWORD_SOURCE --databases DATABASE_NAME | ssh MY_SSH_USER@DESTINATION_SERVER_IP "mysql -uSQL_USER_DESTINATION -pSQL_PASSWORD_DESTINATION" rsync, to run on source server (BUILD_DIRECTORY is the main PW directory path, /var/www/SITE_NAME/html/ is the destination directory: rsync -avh --delete-delay --exclude-from=deploy-excludes.txt -e ssh BUILD_DIRECTORY SSH_USER@DESTINATION_SERVER_IP:/var/www/SITE_NAME/html/ deploy-excludes.txt: site/assets/cache/* site/assets/sessions/* I'm not 100 % sure about syntax for "cache/*", I use "site/assets/cache/" in my case. Idea in your case is to copy empty folder without content, in case PW doesn't create it at runtime. Note that I added a SSH key on destination server, it's why I don't need to specify SSH user and password in commands. -
Yes, sometimes I want to post some random message but I don't find a place for this. Today, I was looking for a Drupal forum, and when I found this, I thought it was created to discourage people from asking for help. ? Look at a topic, seriously...
-
Hey, I think this forum could benefit from a pinned thread where we can talk about anything and everything without needing to create a new topic, like a pub conversation that lasts all night, but goes on for years. ? If you are a moderator and like the idea, please pin this topic, otherwise just delete it, I won't hold it against you. ?
-
Custom page class does not work by alternate template file
da² replied to Migu's topic in General Support
Hi @jmclosas, Could you give more informations on your code, and the complete stack trace? I have a template "game-championship-summary" that uses the template file "events-summary", the custom class is named GameChampionshipSummaryPage, and this is working. I bet you wrote the $page->getTest() yourself (or it comes from a module), because in ProcessWire core I can't find a single "getTest". ? -
access a related page templatefield's label in the current user language
da² replied to froot's topic in API & Templates
@froot Try to replace "label" by "getLabel()". https://processwire.com/api/ref/field/get-label/ -
Yes, looks like there are a few bugs in change detection, I reported a similar one recently: https://github.com/processwire/processwire-issues/issues/1947 You could also try setAndSave('property', value) or save('property'), or reassigning the field to the page...
-
Reading the Ryan message, the key is to load the field unformatted. $field = $page->getUnformatted('myImageField'); $field->deleteAll(); $page->save(); Be sure to dot that before to investigate deeper. ?
-
This is an important thing to know about ProcessWire, also outside of hooks. ? I was modifying a page "P", that request modification of related pages, and when saving related pages before the page P, the page P fields were reset, so the changes were not saved. I was already using uncacheAll=false in my hooks, but forgot how important it is when saving several pages anywhere else. So I added a method on my base page class: class BasePage extends Page { public function saveSafe(bool $of = null): bool { $success = true; try { $this->save(options: ['noHooks' => true, 'uncacheAll' => false]); } catch (WireException $e) { $this->wire->log->error($e); $success = false; } if (is_bool($of)) $this->of($of); return $success; } } The $of parameter makes it quicker to restore output formatting after saving. This is the class that all my custom pages inherits, I have some more stuff on it also. DefaultPage inherits it too, so any page that have no specific custom class page also have this method.
-
@cpx3 You store the products in the session or a cookie, you don't need the session_id to do that.
-
[Solved] Load a single repeater item by specifying parent page
da² replied to da²'s topic in General Support
Yes this is working, I don't really understand how because the field leaderboardCategories is not used in the rest of the selector... but that works. ? -
[Solved] Load a single repeater item by specifying parent page
da² replied to da²'s topic in General Support
Nope. ? -
[Solved] Load a single repeater item by specifying parent page
da² posted a topic in General Support
Hi, I think of refactoring several pages into a repeater, but I need to be able to load a single repeater item by specifying the parent page... and I'm struggling. Here the actual code: $pages->find("template=repeater_leaderboardCategories, carsOrCarClasses=5941, include=all"); The result: ProcessWire\PageArray Object ( [count] => 2 [items] => Array ( [LeaderboardCategoriesRepeaterPage:0] => Array ( [id] => 6065 [name] => 1722945441-3239-1 [parent] => /cockpit/repeaters/for-field-277/for-page-6057/ [template] => repeater_leaderboardCategories [title] => Array ( [data] => cat2 [data5865] => ) ) [LeaderboardCategoriesRepeaterPage:1] => Array ( [id] => 6070 [name] => 1722946036-4849-1 [parent] => /cockpit/repeaters/for-field-277/for-page-6066/ [template] => repeater_leaderboardCategories [title] => Array ( [data] => champ 2 2 [data5865] => ) ) ) [selectors] => template=repeater_leaderboardCategories, carsOrCarClasses=5941, include=all ) I get two repeater items, but coming from 2 different pages. So I want to specify the parent page of the repeater (id=6057), but none of my tests have worked. I've tried a lot of things like this: $pages->find("template=repeater_leaderboardCategories, carsOrCarClasses=5941, include=all, parent.getForPage=6057"); I also tried to search from the parent page directly: $page = $pages->get(6057); $page->leaderboardCategories('carsOrCarClasses=5941'); This works with a ProFields Table, but the repeater loads all items. Any suggestion? -
I think this is the wrong approach. Country is not relevant if we are only talking about language. Many countries have several languages, and each language is used in several countries. In some countries a part of the country uses one language and the other one another language (Belgium for example). From the visitor point of view this is confusing, a visitor thinks in term of language, not country. In terms of implementation you are choosing the more complex solution, if PW is straight forward for managing languages, you'll have to develop a solution over this language management for managing countries.
-
page disappears in frontend when link changes (url not updated)
da² replied to floko's topic in Getting Started
The only field that is related to page url is the field "name", not "title" or custom field. It's located under "Parameters" tab. But you'll probably need to edit PHP code in template files, that depends on how the links are created. -
Probably here you should catch Error too: catch (\Exception | \Error $e) I use similar code with Twig, rendering an error template if any error. class Twig { public static function render(string $name, array $parameters = []): void { if (NoticeManager::hasNotice()) $parameters['rfroNotices'] = NoticeManager::render(); $parameters['templatesUrl'] = wire()->config->urls->templates; $parameters['homePage'] = wire()->pages->get('/'); $parameters['buildVersion'] = BUILD_VERSION; $parameters['buildDate'] = BUILD_DATE; /** @var TemplateEngineFactory $twigEngine */ $twigEngine = modules('TemplateEngineFactory'); try { echo $twigEngine->render( $name, $parameters ); } catch (Exception|Error $e) { // Catching everything if (wire()->config->debug) // If debug, throw the error with stack trace throw new Error("{$e->getMessage()}\n{$e->getTraceAsString()}"); wire()->log->error($e); $parameters['errorPage'] = wire()->page->path; try { // Try to render my error template, that shows something nicer for users. echo $twigEngine->render('error', $parameters); } catch (Exception|Error) { // It may happen, rarely, that the error is located at a lower level in my Twig structure (inheritance...), // so I display a very basic template that uses no code and can't fail. echo $twigEngine->render('error-safe', $parameters); } } } }