Leaderboard
Popular Content
Showing content with the highest reputation on 01/18/2021 in Posts
-
Hi @Richard Jedlička You can try public function executeSome() { $this->headline('Your page'); $this->breadcrumbs->pop(); $this->breadcrumb('../', $this->_('Some page')); $this->breadcrumb($this->getProcessPage()->url(), $this->_('Some other page')); }3 points
-
Hi everyone, Here's a new module that I have been meaning to build for a long time. http://modules.processwire.com/modules/process-admin-actions/ https://github.com/adrianbj/ProcessAdminActions What does it do? Do you have a bunch of admin snippets laying around, or do you recreate from them from scratch every time you need them, or do you try to find where you saw them in the forums, or on the ProcessWire Recipes site? Admin Actions lets you quickly create actions in the admin that you can use over and over and even make available to your site editors (permissions for each action are assigned to roles separately so you have full control over who has access to which actions). Included Actions It comes bundled with several actions and I will be adding more over time (and hopefully I'll get some PRs from you guys too). You can browse and sort and if you have @tpr's Admin on Steroid's datatables filter feature, you can even filter based on the content of all columns. The headliner action included with the module is: PageTable To RepeaterMatrix which fully converts an existing (and populated) PageTable field to either a Repeater or RepeaterMatrix field. This is a huge timesaver if you have an existing site that makes heavy use of PageTable fields and you would like to give the clients the improved interface of RepeaterMatrix. Copy Content To Other Field This action copies the content from one field to another field on all pages that use the selected template. Copy Field Content To Other Page Copies the content from a field on one page to the same field on another page. Copy Repeater Items To Other Page Add the items from a Repeater field on one page to the same field on another page. Copy Table Field Rows To Other Page Add the rows from a Table field on one page to the same field on another page. Create Users Batcher Allows you to batch create users. This module requires the Email New User module and it should be configured to generate a password automatically. Delete Unused Fields Deletes fields that are not used by any templates. Delete Unused Templates Deletes templates that are not used by any pages. Email Batcher Lets you email multiple addresses at once. Field Set Or Search And Replace Set field values, or search and replace text in field values from a filtered selection of pages and fields. FTP Files to Page Add files/images from a folder to a selected page. Page Active Languages Batcher Lets you enable or disable active status of multiple languages on multiple pages at once. Page Manipulator Uses an InputfieldSelector to query pages and then allows batch actions on the matched pages. Page Table To Repeater Matrix Fully converts an existing (and populated) PageTable field to either a Repeater or RepeaterMatrix field. Template Fields Batcher Lets you add or remove multiple fields from multiple templates at once. Template Roles Batcher Lets you add or remove access permissions, for multiple roles and multiple templates at once. User Roles Permissions Batcher Lets you add or remove permissions for multiple roles, or roles for multiple users at once. Creating a New Action If you create a new action that you think others would find useful, please add it to the actions subfolder of this module and submit a PR. If you think it is only useful for you, place it in /site/templates/AdminActions/ so that it doesn't get lost on module updates. A new action file can be as simple as this: <?php namespace ProcessWire; class UnpublishAboutPage extends ProcessAdminActions { protected function executeAction() { $p = $this->pages->get('/about/'); $p->addStatus(Page::statusUnpublished); $p->save(); return true; } } Each action: class must extend "ProcessAdminActions" and the filename must match the class name and end in ".action.php" like: UnpublishAboutPage.action.php the action method must be: executeAction() As you can see there are only a few lines needed to wrap the actual API call, so it's really worth the small extra effort to make an action. Obviously that example action is not very useful. Here is another more useful one that is included with the module. It includes $description, $notes, and $author variables which are used in the module table selector interface. It also makes use of the defineOptions() method which builds the input fields used to gather the required options before running the action. <?php namespace ProcessWire; class DeleteUnusedFields extends ProcessAdminActions { protected $description = 'Deletes fields that are not used by any templates.'; protected $notes = 'Shows a list of unused fields with checkboxes to select those to delete.'; protected $author = 'Adrian Jones'; protected $authorLinks = array( 'pwforum' => '985-adrian', 'pwdirectory' => 'adrian-jones', 'github' => 'adrianbj', ); protected function defineOptions() { $fieldOptions = array(); foreach($this->fields as $field) { if ($field->flags & Field::flagSystem || $field->flags & Field::flagPermanent) continue; if(count($field->getFieldgroups()) === 0) $fieldOptions[$field->id] = $field->label ? $field->label . ' (' . $field->name . ')' : $field->name; } return array( array( 'name' => 'fields', 'label' => 'Fields', 'description' => 'Select the fields you want to delete', 'notes' => 'Note that all fields listed are not used by any templates and should therefore be safe to delete', 'type' => 'checkboxes', 'options' => $fieldOptions, 'required' => true ) ); } protected function executeAction($options) { $count = 0; foreach($options['fields'] as $field) { $f = $this->fields->get($field); $this->fields->delete($f); $count++; } $this->successMessage = $count . ' field' . _n('', 's', $count) . ' ' . _n('was', 'were', $count) . ' successfully deleted'; return true; } } This defineOptions() method builds input fields that look like this: Finally we use $options array in the executeAction() method to get the values entered into those options fields to run the API script to remove the checked fields. There is one additional method that I didn't outline called: checkRequirements() - you can see it in action in the PageTableToRepeaterMatrix action. You can use this to prevent the action from running if certain requirements are not met. At the end of the executeAction() method you can populate $this->successMessage, or $this->failureMessage which will be returned after the action has finished. Populating options via URL parameters You can also populate the option parameters via URL parameters. You should split multiple values with a “|” character. You can either just pre-populate options: http://mysite.dev/processwire/setup/admin-actions/options?action=TemplateFieldsBatcher&templates=29|56&fields=219&addOrRemove=add or you can execute immediately: http://mysite.dev/processwire/setup/admin-actions/execute?action=TemplateFieldsBatcher&templates=29|56&fields=219&addOrRemove=add Note the “options” vs “execute” as the last path before the parameters. Automatic Backup / Restore Before any action is executed, a full database backup is automatically made. You have a few options to run a restore if needed: Follow the Restore link that is presented after an action completes Use the "Restore" submenu: Setup > Admin Actions > Restore Move the restoredb.php file from the /site/assets/cache/AdminActions/ folder to the root of your site and load in the browser Manually restore using the AdminActionsBackup.sql file in the /site/assets/cache/AdminActions/ folder I think all these features make it very easy to create custom admin data manipulation methods that can be shared with others and executed using a simple interface without needing to build a full Process Module custom interface from scratch. I also hope it will reduce the barriers for new ProcessWire users to create custom admin functionality. Please let me know what you think, especially if you have ideas for improving the interface, or the way actions are defined.1 point
-
Hi When using the module with version 1.1.1 I have a strange issue with using the "StdClass". I keep getting the error as you can see in the screenshot "Cannot use object of type stdClass as array". In previous projects similar code was working fine, something broken with this? My calls are just regular GET requests. If I don't use the "stdclass" I'm not receiving errors anymore.1 point
-
yes, again, the issue was something like that. Many thanks!1 point
-
Hi Teppo, you were completely right (of course ;-)). The module is working fine on HTTPS! Thanks.1 point
-
A couple of real world examples, just in case they help in addition to @Zeka's answer. https://github.com/adrianbj/ProcessAdminActions/blob/5d77e86ae20f016d3b9ce1abd791b1af9e82451e/ProcessAdminActions.module.php#L683 https://github.com/adrianbj/AdminRestrictBranch/blob/4964a3f5b83338f7313f7c6daeefe6c6793640b0/AdminRestrictBranch.module.php#L131-L1441 point
-
The json_decode() function has an "associative" argument that you can set to true: $meevo_response_array = json_decode($meevo_response, true); Or you can use the core wireDecodeJSON() function which does this automatically. $meevo_response_array = wireDecodeJSON($meevo_response);1 point
-
I've added 1.5 million pages. It works faster than Wordpress, but server response time is still high - 0,8-2 s. I have 4 Cores, 4 GB RAM and SSD disk, Mysql 8 and PHP 7 I'll keep you updated1 point
-
@fruid - this works: $this->wire('files')->unlink($file->filename); but the problem is that in your example, your code never gets here because you have "return true" or "return false" in the if/else above this point. I simplified things right down so obviously this doesn't handle the processing of the CSV file, but this is basically what you want so that you are unlinking before returning true. protected function executeAction($options) { $parent = ''; $parent_title = ''; $url = config()->paths->assets.'cache/AdminActions/'; if(count($options['csv_upload'])) { $n = 0; $file = $options['csv_upload']->first(); $fp = fopen($file->filename, 'r'); fclose($fp); $this->wire('files')->unlink($file->filename); return true; } else { $this->failureMessage = 'Please upload a CSV file'; return false; } }1 point
-
I think you're better off not using FieldtypeCache. See this issue for some discussion: https://github.com/ryancramerdesign/ProcessWire/issues/1577 And I remember Ryan commenting somewhere that he's thinking of removing it from the core. The simplest thing if you want to merge multiple fields into a single field for search purposes is to use the SearchEngine module. Or if you want to go more hands-on it's not difficult to populate a hidden "index" textarea field from other field values using a Pages::saveReady hook. $pages->addHookAfter('saveReady', function(HookEvent $event) { $page = $event->arguments(0); if($page->template == 'your_template') { $index = $page->title; if($page->body) $index .= ' ' . strip_tags($page->body); foreach($page->tags as $tag) $index .= ' ' . $tag->title; $page->index = $index; } });1 point
-
Interesting approach. It deserves further investigation, I think. If I understand it correctly, you propose another set of children – separated from the current set – which is used for layout only perhaps? Reading other's comments, I think most of us do not ask for a "Gutemberg only like" feature, instead, most of us need a way to implement a builder which is similar to the current repeater(matrix) based solutions others have presented in the forum, but geared towards layout + building. Editor.js could simply be another fieldtype, just an alternative to CKEditor. You and/or your client could decide which one to build upon your "RTE editing needs".1 point
-
Better private pages for note-taking, intranets, extranets: I happen to use ProcessWire as public as well as a private note-taking tool. While ProcessWire works really well as a public website, the private website is harder. As a webmaster I want to protect the entire site, a branch (root page and it's children) or a page so that I know my page(s) stay private. Much like Adrian's Page Protector module. As a webmaster I want the page tree to show if a page is protected so that I don't worry if it's protected. As a webmaster I want page protection to be built-in and work with Page Status. As a web designer I want to present public pages to visitors and public+protected pages to permitted users. As a webmaster I want to grant access / permission to specific users and roles. As a webmaster I want to ensure that private / protected pages stay private. Today I might easily publish a page by mistake (when using Unpublished status to control private pages): Benefits: This change will make ProcessWire attractive in a whole new game (intranets, extranets, note-taking, private online knowledge-bases and much more).1 point
-
@Zeka Currently you can create a class like BlogPostPage and it automatically be used as the class for all pages using template "blog-post". You mentioned the PagesType class, which is used by things like Users ($users), Roles ($roles), Languages ($languages), etc. as an alternative to the $pages API var. To make sure I understand what you mean, are you saying that you'd like to be able to create a class like this: class BlogPostPages extends PagesType {} And then you'd get this API var ($blogPostPages) that limits itself to pages using template "blog-post": $posts = $blogPostPages->find("date>last year, sort=date"); Is that what you mean, or something different?1 point
-
Thanks. I worked out the first approach which works as a quick fix, but it's good to know the second one will work as well, as I think from an OO programming perspective, it's clearer to use the second option as I am effectively setting a page property, just I'm doing it at runtime, and as a non-persisted property.1 point
-
Part of the process that happens when you set a Files or Images field value is the copying of the file to the page's folder in /site/assets/files/. The solution is not to set the Pageimage to the field. Just use some variable name like... $header_image = getHeaderImage($page); ...or if you want it stored on the Page object then invent some property name that isn't a field name, e.g. $page->the_header_image = getHeaderImage($page);1 point
-
1 point
-
One other suggestion: if any PW selectors turn out to be slow across so many records, try using the RockFinder3 module (https://github.com/baumrock/rockfinder3).1 point
-
@netcarver 's answer pretty much covers this. My advice would be to watch out for anything involving counting, such as pagination and complex selectors using the Selector API.1 point
-
That's basically impossible for anyone to answer as there are so many other variables involved than just the row count and your machine specs. It will also depend on how much of that data needs to be loaded per page view, how many requests per second you expect to handle, will you be using caching, are there background updates happening, are the tables correctly indexed and using the most suitable storage engine, how many sessions will be active at peak, will you be triggering external API calls as part of the page views, what about asset loading - all assets optimised, and how often you'll need to be updating rows in the DB, do the pages involve JS rendering anything on the frontend etc. etc. I think you'd be better off setting a target for acceptable page loading times and then asking "What do I need to do to get 80% of my page loads to this time or better?" You also need to consider if PW's API is a good fit for your programming needs and if the Admin interface is suitable for you and any users who may need access to the admin. I'd suggest setting your speed goals and then trying an import of a subset of your data and then seeing how your resource needs and page speeds scale going from say 100 thousand to 200 thousand rows and then extrapolating from that. If you do try out PW, please keep us updated with your results.1 point