Jump to content

BitPoet

Members
  • Posts

    1,122
  • Joined

  • Last visited

  • Days Won

    47

Everything posted by BitPoet

  1. In site 1, I'd guess that there's a spot where you're missing quotes in $_SERVER['HTTP_HOST'] (i.e., $_SERVER[HTTP_HOST], which will with strict mode turned off interpret HTTP_HOST as the name of a constant in the current namespace). The error in site 2 points to a missing pdo_mysql extension, so make sure that it's activated and enabled in php.ini.
  2. I think we've talking past each other a bit, so let me see if I can word it differently. The cache should never return an expired value, but I can understand that the strange behavior in your tests 5 and 6 suggests differently. If you don't want to lose a value, don't let it expire. Instead, put the logic to overwrite the cached value with a newer one when your API call is successful into your code. And perhaps store the last retrieval time in your cached value, so you have the creation timestamp you mentioned. Perhaps code says more than a thousand words: <?php /** * Code for Cron Job */ $apiResult = your_api_call(); $cachedResult = json_decode($cache->get('yourcachekey'), true); if($apiResult) // Only if API call was successful if(!$cachedResult || $cachedResult['created'] < time() - 300) { // Cache entry older than 5 minutes, write new value to cache $cache->save('yourcachekey', json_encode(['created' => time(), 'apiResult' => $apiResult], WireCache::expireNever); } } /** * Code for frontend use of API data */ $cachedResult = json_decode($cache->get('yourcachekey'), true); $apiResult = $cachedResult['apiResult']; if($apiResult['created'] < strtotime('-1 month')) { // Deal with a stale cache value that hasn't been updated in over a month here }
  3. Nice overview! For full fledged field types, you'll often also want to implement Fieldtype::getConfigAllowContext and Inputfield::getConfigAllowContext. They return an array with the names of those config fields defined in their respective getConfigInputfields method that may be overridden in template or fieldgroup context. The Inputfield class by default returns these config fields: return array( 'visibility', 'collapsed', 'columnWidth', 'required', 'requiredIf', 'requiredAttr', 'showIf' ); So make sure to call parent::getConfigInputfields first, then add your own config inputs. A good example is how InputfieldText does this: public function ___getConfigAllowContext($field) { $a = array('initValue', 'pattern', 'placeholder', 'maxlength', 'minlength', 'required', 'requiredAttr'); return array_merge(parent::___getConfigAllowContext($field), $a); } Now the initValue, pattern, placeholder, maxlength, required and requiredAttr settings can be overridden in each template the field is used in.
  4. In that case, the most straight forward approach is to add a custom permission through the backend (e.g. 'import-pages'), hook before your module's execute method and check if the current user has this permission. Untested code for site/ready.php: <?php namespace ProcessWire; wire()->addHookBefore("ImportPagesCSV::execute", function(HookEvent $event) { if(wire('user')->isSuperuser() || wire('user')->hasPermission('import-pages')) return; $event->return = '<h3>You do not have permission to import pages. Please contact the administrator!</h3>'; $event->replace = true; }); Of course, this still leaves the backend menu item in place, but unlike modifying third party modules, it is upgrade safe.
  5. The word "tag" is very a technical thing. Call them "keywords" instead, and more than half of your users' questions will evaporate instantly. That's what I learned at my current job when I trained colleagues and heard the relieved insight, "Oh, you're talking about keywords!" rather often. The other half you'll only catch with real-life examples. Depending on the number of pages and content editors, it might make sense to moderate keywords for a while until everybody got their footing. Just a small Pages::published hook that sends a backend link to the new page to the tags moderator so they can give the chosen tags a once over and clarify with the editor what makes sense and what doesn't. I did that with a small knowledge base section for our technical sales managers when they went into a new market area, and we used the direct feedback to fill the tags (later keywords) FAQ with examples and explanations that made sense to them. Actually, that's no longer the case. Since 3.0.177, you can use the new InputfieldTextTags, and choosing a delimiter other than space will allow multi word tags.
  6. As a hobby writer, I do have my doubts there. Natural language is the second most ambiguous thing in the world, right after Schrödinger's cat.
  7. Why don't you split your cron job's logic to use two separate cache calls? $cache->get('cachetest') to read your cached data without expiring it, and $cache->save('cachetest', '+1 month', $apiresult) only if your api call was successful. You'll always have the last successful call's result in your cache this way, and it will be much cheaper than full fledged pages.
  8. I'd say it's just a question of a missing "echo" in front of page()->render('callout');
  9. The short answer is: don't use a lifetime in calls to $cache->get(). Somewhat longer: it looks like a bug to me. It certainly doesn't do what the docs say, namely check the age of an entry. The behavior is a bit different if you specify a template function as the third value, as that uses the lifetime to fill the cache with the function's return value, but that's neither here nor there. In your case (unless I'm misinterpreting what you wrote), the only call that needs a lifetime is the one to $cache->save() in your cron job. The other parts can just call $cache->get('cachetest') and be happy (unless the cache wasn't updated within the last month).
  10. is_callable doesn't resolve namespaces. It should work if you use "ProcessWire\\custom_debug_if". I'm not sure why ProcessWire.php doesn't use wireIsCallable() at that spot. Might be worth raising an issue.
  11. Also, make sure that your search form and results template use the correct request method (GET vs. POST), as having "<form method='POST'>" in the HTML and reading $input->get->q in PHP would explain the behavior.
  12. It's very likely, as this post in the module's support thread suggest: I'm not familiar enough with ProcessChangelog (nor ProcessDatabaseBackup) to guess at the technical issue behind that, but maybe @teppo as the module's author can shed some light on it.
  13. More likely memory_limit, not post_max_size. The first thing I'd try is to uncache pages in your executeAction method, but if your database is huge (any kind of logging going on like ProcessChangelog?) upping memory_limit might be the way to go.
  14. As @Jan Romero wrote, its more often than not that a link's textual information is generated dynamically from its relationship (e.g. the page/template it's on or that's referenced). For manual entry of link texts, creating separate fields for the link target and the text like you did is the way to go. You can, however, make your developer life easier when you have multiple occurrences of that combination in different templates by wrapping both in another field type. This can be a Repeater if you have multiple entries, or for a single one you can use either FieldsetPage or FieldsetGroup, depending on whether you want the link entry to live under a unique property of your page. With fieldsetgroup it is $page->urlfield and $page->linktextfield, while in fieldsetpage its $page->myfieldsetpagefield->urlfield and $page->myfieldsetpagefield->linktextfield. The former is more performant, while the latter makes it more clear that both fields are related.
  15. Or install @tpr's AdminOnSteroids module which, among many other really convenient shortcuts, adds a "clear" button to PageListSelects.
  16. What's the error message you get? Maybe a stupid question, but did you enable .heic in the image field's allowed extensions?
  17. That's strange. Somewhere along the way, PagePathHistory::__upgrade should have been triggered and added that column. The language_id column was introduced with version 2 of the module, shortly before PW was moved to the new GitHub repo in 2016. There was an identical issue mentioned back then, and Ryan added a self-healing fix in PagePathHistory::getPath, but it looks like he took that out after a few years. You can, however, add that column manually to get rid of the error and put the language_id back into the select: ALTER TABLE page_path_history ADD language_id INT UNSIGNED DEFAULT 0
  18. Behind the scenes, the admin user is a page with the id 41, so you can determine the username by running the following sql query: select `name` from `pages` where `id` = 41; The quickest way to reset the password should be this:
  19. You're inside a function, so there's no global $datetime object. wire('datetime') should do the trick.
  20. Yes. Sorry. Not sure what's the error with wireEncodeJSON, might be a namespace issue or something else. But your code looks fine to me. Maybe outputting $jsConfig in a comment block or calling json_last_error_msg() can give you a clue about the empty array.
  21. By default, the ProcessWire object is only output in the backend or if you have frontend editing active. Otherwise, you need to add it to the html head in your your php template like this: <script> var ProcessWire = {config: <?= wireEncodeJSON($config->js(), true, $config->debug) ?>}; </script>
  22. The topic comes up regularly, so there's already a ton of information in the forum. If url segments for the building template aren't needed, this solution should cover the requirements:
  23. I'd expect that calling $cachedPage->yourcommentfield->renderForm() in your uncached page's template should do what you want.
  24. There's a typo there, it should be "->" instead of ">-", sorry for that. <?php // Expressive version: echo $p->nativeField->get('fifth-row')->value; // If the native field's name adheres to PW's field name rules, you can shorten that: echo $p->nativeField->fifthrow->value; // Stringification returns the stringified value, not the object echo "{$p->nativeField->fifthrow}"; That would be another step further. For now, it's just configuration options for each different kind of input (text, int, float...). I'm not sure if that would offer much advantage over regular fields, but I'll give it some thought.
×
×
  • Create New...