Version: current

     1 <?php
     2
     3 /**
     4  * Задача для автоматической чистки старых версий
     5  * запускать: sake /dev/tasks/ClearHistoryTask
     6  *
     7  * @author dvp
     8  */
     9
    10 class ClearHistoryTask extends BuildTask {
    11
    12     protected $title = 'Clear Page History';
    13
    14     protected $description = "Удаляет старые версии страниц оставляя не более 20 опубликованных и 20 черновых версий";
    15
    16     function init() {
    17         if (!(Director::isDev() || Director::is_cli() || Permission::check("ADMIN")))
    18             return Security::permissionFailure($this);
    19
    20         parent::init();
    21     }
    22
    23     function run($request) {
    24         $deleted = 0;
    25         foreach (DataObject::get('Page') as $page) {
    26             print "<li>Clear old versions for: ". $page->Title . ' #' . $page->ID ;
    27             $del = $page->clearOldVersions();
    28             print ": $del free\n";
    29             $deleted += $del;
    30         }
    31         print "\n\n<hr>Done: $deleted versions deleted.\n";
    32     }
    33 }
    34

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -