Version: current

     1 <?php
     2
     3 class FillLinkTrackingTask extends BuildTask {
     4     protected $description = 'Update page - files link tracking for attached files and images';
     5
     6     function run($request) {
     7         if (class_exists('DataObjectFileTrackingDecorator')) {
     8             $baseClasses = ClassInfo::subClassesFor('DataObject');
     9             unset($baseClasses[0]); // выкидываем DataObject
    10             foreach($baseClasses as $className) {
    11                 if (!ClassInfo::is_subclass_of($className, 'SiteTree')) {
    12                     if (!in_array($className, DataObjectFileTrackingDecorator::$skip_classes)) {
    13                         if (!ClassInfo::is_subclass_of($className, 'File')) {
    14                             if ($objects = DataObject::get($className)) {
    15                                 foreach($objects as $object) {
    16                                     $object->saveTracking();
    17                                     if ($db = $object->db()) { // для HTMLText сохраняем трекинг для ссылок на файлы и вложенные картинки
    18                                         foreach($db as $name=>$type) {
    19                                             if ($type == 'HTMLText') {
    20                                                 $field = new HtmlEditorField($name);
    21                                                 $field->setValue($object->{$name});
    22                                                 $field->saveInto($object);
    23                                             }
    24                                         }
    25                                     }
    26                                 }
    27                             }
    28                         }
    29                     }
    30                 }
    31             }
    32         }
    33     }
    34 }
    35

[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. -