Source of file DeletePostsTask.php
Size: 1,232 Bytes - Last Modified: 2021-12-24T06:35:31+00:00
/var/www/docs.ssmods.com/process/src/code/tasks/DeletePostsTask.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 | <?php class DeletPostsTask extends BuildTask { protected $title = 'Delete blog posts task'; protected $description = 'Deletes all blog posts and any associated comments.'; public function init() { parent::init(); if (!Permission::check('ADMIN')) { return Security::permissionFailure($this); } } public function run($request) { // Are there members with a clear text password? $posts = DataObject::get("BlogEntry"); $count = 0; $commentCount = 0; foreach ($posts as $post) { // Delete comments if (class_exists('Comments')) { $comments = $post->Comments(); foreach ($comments as $comment) { $comment->Delete(); $commentCount++; } } $count++; $post->deleteFromStage('Live'); $post->delete(); } if ($count) { Debug::message("Deleted $count posts"); } else { Debug::message("No posts deleted"); } if ($commentCount) { Debug::message("Deleted $commentCount comments"); } } } |