Jump to content

Peter Falkenberg Brown

Members
  • Posts

    339
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by Peter Falkenberg Brown

  1. Thanks, @AndZyk, But adding the single quote marks didn't work. I still get this error message: Fatal Error: Uncaught Error: Call to a member function date() on null in site/ready.php:12 #0 wire/core/WireHooks.php (1050): ProcessWire->{closure}(Object(HookEvent)) #1 wire/core/Wire.php (485): WireHooks->runHooks(Object(Pages), 'saveReady', Array) #2 wire/core/PagesEditor.php (491): Wire->__call('saveReady', Array) #3 wire/core/PagesEditor.php (455): PagesEditor->savePageQuery(Object(Page), Array) #4 wire/core/Pages.php (799): PagesEditor->save(Object(Page), Array) #5 wire/core/Wire.php (420): Pages->___save(Object(Page), Array) #6 wire/core/WireHooks.php (951): Wire->_callMethod('___save', Array) #7 wire/core/Wire.php (485): WireHooks (line 12 of site/ready.php) Peter
  2. Hi All, Maybe because my brain is fried tonight, but I'm totally stuck on extracting the 4 digit year from a datetime field inside the ready.php file, on saving a page. Here's my code: $pages->addHook('saveReady', function(HookEvent $event) { $page = $event->arguments(0); if ( $page->template == 'book_sales' ) { if ( $page->sold == 1 ) { $page->profit = ($page->sale_price - $page->buy_cost) - $page->transaction_fee; $page->sale_year = $datetime->date($format='Y', $page->getUnformatted(sale_date)); } } }); The line that tries to get the sale_year, i.e. $page->sale_year = $datetime->date($format='Y', $page->getUnformatted(sale_date)); breaks with a bunch of errors. Anyone have the right syntax? Thanks! Peter
  3. Hi @dotnetic, That is BEYOND COOL. One more reason why all of the other "CMS's" should bow down to ProcessWire! Thank you! I shall use it. Best regards, Peter
  4. Hi @dotnetic, (An aside: I created a spreadsheet that does all of this very quickly. Easy as pie. However, in some cases, a PW database might be better, thus my questions. On the other hand, maybe trying to fit PW with the functionality of spreadsheets is a waste of time. You know... the right tool for the job.) Yes, the PagesSum module is exactly what I need. Thank you! But... in the Admin section, with the standard tree of page types (i.e. templates), assuming that I have a branch of pages called "sales," then where and how could I display the sum of those sales pages (from a field called "sale_price") on the admin page? I haven't adequately dug into the task of modifying the admin page. In a custom app, all based on php template docs, I would simply display that total on the apps version of the "home" page, i.e. like the Admin tree page. But in the PW Admin page, I haven't yet learned how to add a routine to display something like that on the top level admin page. Is there a document somewhere in the PW knowledge base on how to do that? I've already made one small modification to the admin's core files in the wire directory, in a file called "AdminTheme.php." In that file, in the routine public function ___getExtraMarkup() I change this code: if($isLoggedin && $this->wire('config')->advanced) { # $parts['footer'] = "<p class='AdvancedMode'><i class='fa fa-flask'></i> " . $this->_('Advanced Mode') . "</p>"; $parts['footer'] = str_repeat('&nbsp;', 10) . "DB: " . wire('config')->dbName . "<br><br>"; } ... so that the admin page would display the name of the database in use (to avoid a dev version using the live db by mistake). ( @ryan Ryan, I think this would be a good addition to the core.) I realize that it's a Bad Idea to modify core files, so in terms of modifications to the admin home/tree page, with the Sum function display, I'm hoping that there's a hook method, or some other way to get that data displayed on the page, without messing with the core files. Thanks! Peter
  5. Hi All, I haven't found this answer in the docs or forums. I know how to program a template that would display multi-page field calculations like a spreadsheet, e.g. with 100 pages, each with a dollar value in a field, display the total dollar value of a subset of the 100 pages based on a "sold" data field value. I know how to put that template / url / page behind a password. What I'm not clear about is whether or not PW has an easier method than that. For example, in the standard admin, create a page/template that has the summary fields in it and pull the calculations from the "item" pages whenever the summary page is accessed or a button is pressed. Or something like that. So that the calculations can be viewed in the admin without having to build a password protected, programmed front-end page. Of course, a spreadsheet can do all this easily, but after thousands of records, it becomes rather unwieldy, in my opinion. What do people recommend? Thanks, Peter
  6. Hi Ryan, When I read about the combo field, it almost seems like a jury-rigged version of a standard MySQL data table with column definitions. When I first came to ProcessWire, I had to get used to its splitting of the fields into separate tables. I'm not an expert DBA kind of person on advanced MySQL queries and indexing and things like complex join SQL statements, but how would you compare the traditional SQL approach of complex queries to both the standard ProcessWire method and the new Combo fields? My question might be too broad; not sure. Peter
  7. Thanks, @jonatan... The solutions above worked perfectly. Because I already had ready.php code to set the name field to the ID, all I had to do was set the allowed template for children to "item" and then set the Name format for children to "Y-m-d-H-i-s." Voilà! Thanks again! Ain't ProcessWire Grand? Peter
  8. Thanks, @jonatan! If I put "id" in that field instead of title, will it automatically skip the name/title page and create the name based on the id? I should have specified more clearly: I want to skip that initial page completely and end up on the edit page, with the name field automatically filled in with the auto-increment ID. Thanks again, Peter
  9. Hi All, I thought I saw that a feature had been developed that allowed one to click "New" to add a new child page, and skip the name field page, and go directly to the edit page, with the name field already having the ID as the value. If that hasn't been developed, is there a way to do that? I've been scouring my posts and searching the forum because I know that I got advice from someone to set the name field to the ID using ready.php, using this code: $pages->addHookAfter('added', function(HookEvent $event) { $page = $event->arguments(0); if($page->template == 'item') { $page->setAndSave([ 'name' => $page->id, ]); } }); ... but I can't find the darn post in the forum. (I'm using the code above.) My client wants to skip the step where he has to add a fake name value (like 'n') which then gets overwritten by the ID, using the code above. Thanks! Peter
  10. Hi Folks, I am stuck, after scouring the API docs, module code, and forum questions. I'm trying to write code that upon the initial pressing of a search button will set the page number to something other than 1. For example, the query might return 50 pages, but I want to start by showing page 7, with the pagination boxes appearing on both sides of the highlighted box 7. Here's my code (setPageNum will only be used if it's an initial search button press (which I'll check with a hidden form field)). $results = $pages->find("$select_limit"); $pager = $modules->get('MarkupPagerNav'); $pager->setNumPageLinks($numPageLinks); $pager->setPageNum(7); $pagination = $pager->render($results); The returned pagination all looks good EXCEPT that it always starts at page 1 instead of page 7, like this: Any help would be greatly appreciated. Peter
  11. Back in 2005/6, I built a SSG/CMS combination application, based on a Perl Framework that I had written. The magazines' editors input their stories via a CMS login, and then, when they were done, they clicked a button that sent a special secure command to the server to run a script that generated all of the pages as static HTML files. It generated thousands of pages blazingly quickly. Having done that, I think ProcessWire with ProCache accomplishes the same thing, since it also writes HTML files. But... ProcessWire is SO much better than my application ever was, for so many reasons. ProcessWire with ProCache gives us the best of both worlds. Peter
  12. You're very welcome, @szabesz! (and thank you!) This thread started with my how-to questions about image migration. Besides the modules that @adrian and @kongondo mentioned, I didn't find any clear documentation about how to deal with image migration with comprehensive detail (I might have missed finding it). Of course, I read a number of pages about image scripting, but I didn't see info that covered all the bases. Adrian expressed skepticism about the stability of the module Kongondo mentioned, and Adrian's module didn't fit my specific needs, so I didn't use either of those modules, and decided to proceed with my own script. But my script didn't deal with cropped images (because I didn't have any), unless they're automatically brought over by the copy command I ran to bring in any image variations. Thus, my script might have missed some important things with images. I'm not sure. I'd love to see a how-to on this very topic, i.e. a comprehensive write-up of how to migrate images and catch every detail. My efforts were a "roll-your-own" attempt to do it, and it worked for me. But I have no confidence that I covered all the details of image migration. If I did, I'd love to hear about it. 🙂 Peter
  13. Hi All, I've added routines to the script to create a file of hrefs in the body field, and also a file of 301 redirects for an .htaccess file. There are so many edge cases with internal hrefs that I decided to edit them by hand, based on the list created. (For example, an href that links to a second internal PW page on the target domain that PW's url system on the source domain doesn't know about.) I also moved the chown command to include pages that didn't have images, because the file dir has to be owned by the domain and running the script as root ends up making the file dir owned by root. Again, I realize that this script may only serve a very small group of people who need to do exactly what I needed it for: to migrate many sections of pages from one PW domain to another PW domain that had a different section structure. I've successfully and quickly moved many sections and pages as of now, so I'm confident that the script is doing what I needed. If someone else finds it useful, that's grand. 🙂 Here it is, below. Click the "reveal hidden contents" icon below to see it. Peter
  14. Hi @szabesz, Good idea... I deleted the 1st version of the script and put the second one in a spoiler. I couldn't figure out how to delete an empty spoiler or code block. Do you know how? Edit: I figured it out: just go below the empty box and hit the backspace key until it's gone. 🙂 Thanks again, Peter
  15. Hi All, I've brought my wee script forward to the point of functionality for my use, minus a couple of things I'll be adding, like a routine to create a list of 301 redirects that I'll be pasting into my .htaccess file on the "old" domain. I'm also going to write a separate small script to click through pages to migrate that will create a list of href's in each page's body text, so that I can see if they have to be edited. In my case, and my experience, href's can have so many variations, including links to external pages, links to internal PW pages that have been moved *internally*, and links to PW pages that have moved to an external site (e.g. the site being migrated to, using a different url). So I'm not trying to incorporate href modification into the script at this time. I realize that Adrian @adrian has created a very complex and thorough blackbox module for migrations. My script is in no way a replacement for his *much more* sophisticated module. As I mentioned, and as I've noted in the script, I wrote this for a very narrow use-case that may only be useful to me. No idea, actually. I'm eager to dig deeper and deeper into ProcessWire, and move from my own procedural code method into object-oriented code. Lot's of catching up to do, since for the last 13 years I've been managing servers, etc, and didn't code all day, every day. But my oh my, I LOVE ProcessWire. What a joy to use. 🙂 EDIT: May 26, 2020: I've added the routines listed above to v1.1, pasted in a new response below, dated May 26. I also fixed an error with the chown action. See post further down, for the script. Peter
  16. Hi @adrian, I ran the exporter and importer on 1 page, and had the following issues: (I used Append as you suggested.) - The template file was still overwritten - the parent page was imported, probably because the parent page didn't exist in the target site (by design). (I only wanted to migrate the pages under one section to a new section in the target site.) - the images and pdf's were in the zip file but they did not upload to the files/ID dir - the links in the body text still had the old id in the source. - and when I selected "Edit Imported Content" it failed and produced an error - "Missing required ZIP or JSON Source" (when I didn't select that, the second time, it worked, but with the issues above) Yours, Peter
  17. Hi @kongondo, Great suggestion! So much better. On your comment about the find v. get -- you are correct, but that was just a test bit of code. My real export will have multiple pages via a find. Thanks VERY much for your help! Peter
  18. Thanks, @Ivan Gretsky and @kongondo, My old site is on PW 3.0.42, whereas the module is in 3.0.72. My new site is on 3.0.148. Looks like I'll have to upgrade. Peter
  19. Hi @kongondo, You wrote: I looked for that in my Modules setup and also on the PW modules page, and couldn't find it. Do you have a link to it? Thanks, Peter
  20. Hi @adrian, I installed your excellent Migrator module, and saved a zip file for the one page that I've been testing. After inspecting the zip file, I noted that you do indeed bring over the template file and the field structure. In my case, my destination install has identical fields already, but in some cases the the fields or template files might conflict, so overwriting would be a problem. I didn't see a selection to only migrate content, and not fields and templates. It seems to me that your module is perfect for a certain use case, but not necessarily for mine, which only involves migrating content. Unless I missed something. 🙂 Peter
  21. Hi @adrian, Yes, I can see that your Migrator module looks really fantastic. I'll take a look at it. I still want to deepen my knowledge of the image steps, however. I did notice that your list of migrated items includes the cropped images, which I did not address, partly because I didn't have any cropped images. Thanks again! Peter
×
×
  • Create New...