Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/26/2019 in all areas

  1. I just want to share my findings from today when I wanted to create one million pages quickly: First, via Tracy Console: ini_set('max_execution_time', 150); $last = $pages->findOne("parent=/data,include=all,sort=-id"); $last = (int)$last->title ?: 0; for($i=$last+1;$i<$last+1000;$i++) { // create page $p = new Page(); $p->template = 'basic-page'; $p->parent = '/data'; $p->title = $i; $p->save(); l("saved page $i"); $pages->uncacheAll(); gc_collect_cycles(); } d('done'); It started at 23 pages per second: And at the end of the 150 seconds it was already down at 4 pages per second: Testing without logging: Memory usage also increased proportionally. Finally running a PHP script from the command line that bootstrapped PW worked well: <?php namespace ProcessWire; $time_pre = microtime(true); include("../../../index.php"); // bootstrap ProcessWire $last = $pages->findOne("parent=/data,sort=-id"); $i = (int)(string)$last->title ?: 0; // multilang quickfix convert to string // foreach($pages->find('parent=/data') as $p) { // $p->delete(); // echo "deleted $p\n"; // } // return; $i++; $num = 0; while($i <= 1000000) { // create page $p = new Page(); $p->template = 'basic-page'; $p->parent = '/data'; $p->title = $i; $p->save(); $pages->uncacheAll(); gc_collect_cycles(); $num++; echo "done: $num ($i)\n"; $i++; } function convert($size) { $unit=array('b','kb','mb','gb','tb','pb'); return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; } $time_post = microtime(true); $t = $time_post - $time_pre; $m = memory_get_usage(); echo "created $num pages in " . round($t, 3) . "s, " . round($t/$num, 3) . "s per page, used " . convert($m) . " memory\n"; Benefits: quick runs in the background and does not lock the site direct feedback via echo without creating huge log files cancel via ctrl+c any time easy persistant saving of your scripts
    9 points
  2. Chaining is based on the idea that your method returns a self-reference, i.e. "return $this", after which you can access another method from the returned object. In your example when you leave $value param of the text() method empty (so that it defaults to "null"), the method returns "$this->text" (which is a string or null) instead of an object – and you cannot use a string (or null) for chaining (it doesn't have any methods). In other words: even if "$this->text" had a non-null value, you still couldn't use it for chaining, 'cause it would return a string and not a self-reference to the containing object ? Based on your code it looks like text() without a $value is supposed to work like a getter, returning the text (string), so technically this is how it's supposed to work. The most obvious option would be defining another method – perhaps something like setText(string $value = null) – that sets the value but always returns $this, and never the value itself. Or you could just modify the text() method so that it cannot be used as a getter for the value, i.e. make that always return $this. Hope this helps a bit ?
    6 points
  3. Short reply: There's no built-in way to move files around like that. However, you could clone the page as many times as you need, and then go back in and delete everything you don't need anymore.
    3 points
  4. There has been a small update on this module thanks to @Jonathan Lahijani. @Jonathan Lahijani added: PHP files can have a comment called "Description" at the top of the file which will be displayed in the dropdown if it exists. Check this option to disable it.
    3 points
  5. True. In my case, I used $log to save the memory usage results to file to get an average. After that, I switched to Tracy but was well aware of how much memory my script was actually using vs any additions from Tracy :-).
    2 points
  6. Just to expand on this, having seperate methods for getting and setting are preferable because you can use typehints to declare argument and return types. This way, your methods become more robust (invalid arguments produce errors instead of propagating through your application and causing errors elsewhere), and your IDE / code editor can use them to provide better hints while using the methods. If you have just one method for both, you can't use a return typehints, because the function might return a string or an object. To expand on your two methods: public function setText(string $value): self { $this->text = trim($value); return $this; } public function getText(): string { return $this->text; } I'm looking forward to PHP 7.4 which will have typed class properties. Then we'll be able to get rid of the getText method altogether: public string $text; public function setText(string $value): self { $this->text = trim($value); return $this; }
    2 points
  7. all well, don't stress yourself. probably you are faster with your download and the installation than i learned github ?
    2 points
  8. Sorry mate, still not downloaded a Windows image as I am now on a 4G router, no more fiber ? I have to retrieve it from a friend this afternoon or tomorrow, again stay tuned ?
    2 points
  9. Well, that would not be a problem at all, but don't you think this would be a good opportunity to create an account there and simply click the "new issue" button on your own (https://github.com/processwire/processwire-issues/issues) to show that you are willing to help resolving this issue? Using GIT was one the the major steps forward in the last few years for myself, so I'm quite sure you won't regret. PS: I haven't followed this topic; I'm sorry that I can't provide any help.
    2 points
  10. There already is one, the textarea selector is "textarea:not(.noAutosize)". I haven't checked it yet but in theory it should work. Otherwise you could apply a max-height with CSS that could also help, or perhaps setting the height with !important.
    2 points
  11. https://www.youtube.com/watch?time_continue=48&v=POVOTrGhaDA ? wbmnfktr just beat me halve a minute
    2 points
  12. There is no need to run Windows or WSL(2). Back on Linux with my beloved X1 and the Ubuntu i3 setup. Amazing what you can accomplish when your setup is set up right. Totally weird.
    2 points
  13. Anything that can be done with the API can be turned into an executable action with @adrian's Admin Actions module. And you can make an action available to non-superusers too. There's a built-in "Copy Field Content to Other Page" action that you can use as a starting point. This action doesn't work out-of-the-box for Files or Images fields but it wouldn't be difficult to get it working, especially now that you can use Pagefiles::add() with a Pagefile object so that descriptions and tags get copied over automatically. And if you update the action maybe submit a pull request to the module repo with your changes...?
    1 point
  14. Here is an example of enabling Hanna Code on a textarea field (this one is called body):
    1 point
  15. Welcome to the forums @jarik. Make sure you've enabled Hanna Code as a text formatter for the textarea field where you want it to work. I am in a bit of a hurry. Have a look at the settings of your textarea field (details tab).
    1 point
  16. Just be aware that if you have Tracy calls inside your script (d(), etc), these also contribute to the total memory usage :-). In my test cases (some unrelated work), the amount used by Tracy can be significant.
    1 point
  17. That will be great ?! Thanks for you contribution @MoritzLost
    1 point
  18. thank you for your encouraging words, thx.
    1 point
  19. i have unfortunately not yet dealt with github, so far i have been able to ignore it successfully. if someone wants to do that, i would be very grateful. thx
    1 point
  20. Hello @kongondo, Thank you for the update on the release date, I think most of the users where expecting to hear this. ? I would like to know if you have any plans to create room for a multivendor version or something similar? I have a client who wants to build a website/directory where different users would be able to rent out different used items and the website/site admin retains a fee for each transaction. There are a lot of solid solutions out there at the moment, and I know that it’s a lot of work to do until the single vendor it’s ready... but it would be awesome if you will be able to consider it at least.
    1 point
  21. Thanks @teppo this is a very clear explanation. Chaining is only possible with a reference to the object itself not with a string. You are right: my method for text is a combination of a setter an a getter and the getter will always return a string or null, so no reference to the object itself. So I ended up separating getter and setter into 2 different methods and now it works with or without chaining: public function setText(string $value = null) { $this->text = trim($value); return $this; } public function getText() { return $this->text; } In other forums they also do not recommend to combine getter and setter in one method. I thought that combining both would be an useful and elegant way - so I have learnt something new ?! Thanks! It helps me a lot!!
    1 point
  22. Hello for all. In my projects I use my custom modules, but watch videos and read about Profields and my opinion is that Profields provide rich and elegant solutions to solve task in first post. Also what I like about Profields are "rights and permissions" and agree with @MilenKo . Thanks to ProcessWire, there are always many options how something can be done using only existing fields. As "free-solution" example (for the first post task) is to use independent page tree with small content blocks ("partials") and on desired page using existing PW field to select "partials" (eg. just 1 page reference field, or repeater, or page table). Sorry because I don't write more about this "free solution" example but I don't want to go to off-topic. Differents are how elegant would be final result (UI and UX), flexibility, resources (db tables), is it free or need to pay, or time needed for custom development module(s). Regards.
    1 point
  23. That's why I'm here. ?
    1 point
  24. There is PlayOnLinux which seems to support Adobe pretty well on some distributions. I tried it but was never successfull on Ubuntu, while others on Manjaro/Arch had more success. I'm in the happy situation that I only need XD and nothing else. If ever. I miss it on Linux but... it's not that kind of a show-stopper at all. But yes... having Adobe support on Linux would be really nice. To be honest... it doesn't work that well on Windows too. At least XD crashes at least 10x a day on my Windows 10 setup while doing only minor stuff in it. Life after Adobe - highly recommend.
    1 point
  25. @Smoo Take a look at documentation for Pagefiles https://processwire.com/api/ref/pagefiles/ You can loop throught like // Traversing and outputting links to all files foreach($page->files as $name => $pagefile) { echo "<li><a href='$pagefile->url'>$name: $pagefile->description</a></li>"; }
    1 point
  26. You can post an issue on github, as Ryan may not see this here in the post. But he will see it on Github!
    1 point
  27. Hey gents. I've been asking myself this question for quite a while now and even though I've completed some projects purely and entirely out of PW core + free modules, I've been always envy of the simplicity in code and to minimize the database/website load. As it appears, in times when I had to revise some of the profiles code I was finding a better and simpler approach based on some shared recent or good old (but not forgotten) tricks by all the smart persons presenting this amazing ProcessWire community. The more I analyze the code, the more strong need I feel to get the ProFields module for several reasons: a.) All the advice and help that have lead me to my present skills were kindly given absolutely for free with no questions asked and no matter if the answer was helping me generate some revenue. I am 100% convinced that I "owe" back to the community and its major developers the support (my 5 cents back ? ) b.) Being a bit selfish - I would really like to spend less time on a project while still delivering the same if not much better and simpler solutions. To achieve all this, I would need the tools kindly included in the "ProcessWire toolbox" called ProFields. Initially my plan was to build a few profiles, generate some revenue and then spend some of the finance to purchase the tools needed, however most of the profiles I've built were for personal or close friends/relatives from which I did not generate much out of respect. But I've learned that with the proper tools, even when I am "working for pennies" I can complete the project faster/easier and move on to the next of kind. c.) As it was previously mentioned, everybody is in a need of a stable financial position as otherwise no matter how good is the will, everything seems to be doomed to an end of a failure. By buying the ProFields module, I would not only support the respectful development team, but also the community itself as the new releases, modules, tweaks etc. would keep on going. To me - this seems like a healthy recipe of success. d.) Not sure about others, but at least in Canada I am allowed to claim some work related expenses while working as a self employed, so I have a choice to either give/share my money with the developers team or to give them to the government in the form of taxes. Well, let's just say I got tired of paying taxes ? e.) The words: "free for life" or "use on as many websites you want" got me by surprise. Most of the platforms I am aware of are selling their licenses per user, per device, per website etc. but I have not seen a single one stating that I can use a bunch of modules to sell websites etc. and that can go on and on to as many users as I can convince of my skills. I have some pre-sale questions, but I am sure that everything is as well covered as it is with all the freebies so I will not pose some, wait for answers and waste more time on this. I am about to start working on a new project where I clearly stated that without the tools I need, I won't be participating so I am very much eager to start "playing" soon with all the masterpieces included in ProFields. I just wish that the price was in Canadian dollars or at least I've bought the license at the time when CAD to US was 1.04 to 1, but hey - it is an economy driven situation so there is no one to blame on this other than myself waiting for so long.
    1 point
  28. That can definitely be a bit of a pain, and applies to any migration really ? The good thing about the way WordPress handles internal links is that they are all (assuming they've not been modified via hooks or plugins, and a plugin hasn't been producing loads of "non-standard" links) absolute URLs with predefined prefix for each custom post type, and as such – in a lot of cases – you can just run a string replace on the exported data. If you're working on a copy of the site, you can also use WP-CLI (if you have it installed) and run something like "wp search-replace 'https://OLD' 'https://NEW' --all-tables" before the export. Of course if you move things around a lot, it's not going to be quite as simple.
    1 point
  29. Upgrade Path: Padloper 1 to Padloper 2 I have been getting a number of enquiries regarding upgrading from Padloper 1 to 2. I would to reiterate that whilst there isn't a direct upgrade path, it is still possible to import products from Padloper 1 (or any other shop system for that matter) to Padloper 2 using either the API ($padloper->importProducts($imports);// array/json/csv) or the GUI. However, please note the following: You will have to export products from Padloper 1 yourself. No script will be provided for that. You will have to do any manual cleanup of the data as well as additions to the data yourself. Documentation will be provided about the fields required for the import into Padloper 2, e.g. Product title, description, etc, and any optional fields. Supported import formats are JSON, CSV or arrays. Importing into Padloper 2 does not have to be a one-off exercise. Import will have the option to overwrite/update/skip existing identical products. I hope this clarifies things.
    1 point
  30. I was going to write a tutorial but then I thought I might as well take the next step and turn it into a module: If @tpr wants to include the functionality in AOS and people would prefer that rather than a standalone module then I'm fine with that. ?
    1 point
  31. One more: Loop pages in ProcessWire without building a $pageArray. This is useful for when a find() would return too many results to keep in memory. $selector = "template=pages_template"; // as an example while (1) { $p = wire('pages')->get("{$selector}, id>$id"); // get page with id bigger than previous if(!$id = $p->id) break; // assign current page's id to $id or break the loop if it doesn't exist // do stuff using $p as the current page wire('pages')->uncacheAll(); }; This served me well when I had to modify thousands of pages in one go. Works great with bootstrapping from the terminal because it doesn't affect the viewing of the website.
    1 point
×
×
  • Create New...