Frank Schneider Posted October 25, 2023 Share Posted October 25, 2023 I have a table (Authlogs) where the check ins are stored. There are now 130,000 data records there. Wiw can I delete the old ones by date older than 2020? without manually clicking on each record! Link to comment Share on other sites More sharing options...
bernhard Posted October 25, 2023 Share Posted October 25, 2023 Hey Frank, you are very vague with your information that you give us. Therefore it's not easy to help. If english is a problem for you just write your question in german on deepl.com/translator and copy paste the english version here. 23 minutes ago, Frank Schneider said: I have a table (Authlogs) where the check ins are stored. Which table? A database table? Or PW pages? 23 minutes ago, Frank Schneider said: There are now 130,000 data records there. Wiw can I delete the old ones by date older than 2020? Where is your date stored? In a regular PW field? Then it would be a simple $pages->find("your_date_field<..."); But we don't know anything about your setup, so nobody can really help. 1 Link to comment Share on other sites More sharing options...
Frank Schneider Posted October 26, 2023 Author Share Posted October 26, 2023 Meine Seite ist Authlogs (127000 Einträge) mit dem template authlogs. Darin werden Daten gespeichert Authlog mit dem template authlog. Mein Problem ist, dass meine Rest API langsam reagiert, und ich vermute dass die Datensätze zu groß sind. Jetzt will ich alte Datensätze löschen, bei Processwire kann ich das aber nicht so einfach. Ich müsste jeden anklicken, das dauert mir zu lange. Also muss es ein weg geben diese Blockweise oder per Befehl oder tool z löschen. Gruß Frank Link to comment Share on other sites More sharing options...
AndZyk Posted October 26, 2023 Share Posted October 26, 2023 (edited) Hallo @Frank Schneider, du könntest die Seiten per API $pages->delete() löschen: // Alle Seiten mit dem Template authlogs nacheinander $authlogs = $pages->find('template=authlogs'); foreach ($authologs as $authlogPage) { $pages->delete($authlogPage); } // Alle Seiten der Elternseite mit dem Titel Authlogs rekursiv $authlogsParent = $pages->get("title=Authlogs"); $pages->delete($authlogsParent, true); Einfach irgendwo in einem Template einfügen und die Seite mit dem Template aufrufen. Ansonsten können glaube ich Module wie der ListerPro oder Batch Child Editor Stappelbearbeitung von Seiten. Gruß, Andreas Edited October 26, 2023 by AndZyk Fixed typo Link to comment Share on other sites More sharing options...
Frank Schneider Posted October 26, 2023 Author Share Posted October 26, 2023 Danke das hat funktioniert, der Zähler der Authlogs ändert sich nicht ist das Normal? Link to comment Share on other sites More sharing options...
BillH Posted October 26, 2023 Share Posted October 26, 2023 Another recommendation is the Page Manipulator action of the Admin Actions module. Link to comment Share on other sites More sharing options...
AndZyk Posted October 26, 2023 Share Posted October 26, 2023 15 minutes ago, Frank Schneider said: Danke das hat funktioniert, der Zähler der Authlogs ändert sich nicht ist das Normal? Freut mich zu hören, dass es funktioniert hat. Ohne mehr Informationen, kann ich leider nichts zu dem Zähler sagen. Ist der Zähler ein Feld vom Typ Nummer in einem Template? Ist der Zähler die Gesamtzahl aller Seiten mit dem Template „Authlogs“? Die Seiten mit dem Template „Authlogs“ sollten im Papierkorb sein und je nach Selector, können diese immer noch gefunden und für eine Gesamtzahl dazu gezählt werden. Link to comment Share on other sites More sharing options...
BillH Posted October 26, 2023 Share Posted October 26, 2023 I notice that in the example code the selector for $authlogs is 'template=authologs' (with an extra 'o'). Did you perhaps copy that selector without correcting it? Link to comment Share on other sites More sharing options...
Frank Schneider Posted October 26, 2023 Author Share Posted October 26, 2023 type error Link to comment Share on other sites More sharing options...
Frank Schneider Posted October 26, 2023 Author Share Posted October 26, 2023 Siehe Anhang wegen Zähler Link to comment Share on other sites More sharing options...
BillH Posted October 26, 2023 Share Posted October 26, 2023 The counter is correct: you still have 124019 pages. Perhaps the script is timing out or running out of memory. Try this variation of @AndZyk's script: $authlogs = $pages->findMany('template=authlogs, limit=100'); foreach ($authlogs as $authlogPage) { $pages->delete($authlogPage); } Note: findMany() reduces memory usage; 'limit' reduces the number of pages selected. (And 'authologs' is changed to 'authlogs' in two places.) Does the count now drop by 100? 1 Link to comment Share on other sites More sharing options...
bernhard Posted October 26, 2023 Share Posted October 26, 2023 Ich möchte anmerken, dass ich NICHT eingeladen habe, hier auf Deutsch zu schreiben, denn das widerspricht den Forums-Regeln. Ich habe angemerkt, dass DeepL sehr gut im Übersetzen ist und eine gute Möglichkeit sein kann, wenn man Probleme mit Englisch hat. Die Idee war aber, den Post auf Deutsch zu verfassen, dann mit DeepL zu übersetzen und dann auf Englisch hier zu posten. I would like to note that I did NOT invite people to write in German here, because that is against the forum rules. I noted that DeepL is very good at translating and can be a good option if you have problems with English. But the idea was to write the post in German, then translate it with DeepL and then post it here in English. 3 hours ago, AndZyk said: du könntest die Seiten per API $pages->delete() löschen: // Alle Seiten mit dem Template authlogs nacheinander $authlogs = $pages->find('template=authlogs'); foreach ($authologs as $authlogPage) { $pages->delete($authlogPage); } // Alle Seiten der Elternseite mit dem Titel Authlogs rekursiv $authlogsParent = $pages->get("title=Authlogs"); $pages->delete($authlogsParent, true); CAUTION: This script is likely NOT doing what you want. The selector selects the "authlogs" page, which is the parent page! You want to delete "authlog" pages. CAUTION2: If you change the selector from "authlogs" to "authlog" then it will delete ALL authlog pages, not only old ones. You'll probably want something like this: <?php $cutoff = strtotime("2023-09-01"); $pages->find("template=authlog, your_date_field < $cutoff"); PS: Considering that the selector was wrong that would also explain why it didn't change the page count: You tried to delete the parent page, which is not possible unless you delete all children first. So the script actually did nothing and the count didn't change. 1 Link to comment Share on other sites More sharing options...
AndZyk Posted October 26, 2023 Share Posted October 26, 2023 Sorry, I should have read the question more carefully and not made a typo in my example. I just wanted to give some solutions, based on litte information, but was in a hurry. Ignore my code and use the other examples. 1 Link to comment Share on other sites More sharing options...
BillH Posted October 27, 2023 Share Posted October 27, 2023 I too forgot it was only pages before a certain date, so don't miss @bernhard's suggestion! Meanwhile, I guess that deleting so many pages will cause timeouts or memory problems (I may be wrong!). If it does, you could run the code several times using a suitable 'limit' in the selector. You could do this manually, or perhaps put the code in a shell script and repeat using Cron. Or use LazyCron. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now