public function onAfterWrite()
 {
     parent::onAfterWrite();
     if ($this->isInsert) {
         $blog = new BlogHolder();
         $blog->ParentID = $this->ID;
         $blog->Title = "News";
         $blog->ShowInMenus = false;
         $blog->write();
         $blog->publish('Stage', 'Live');
         $calendar = new Calendar();
         $calendar->ParentID = $this->ID;
         $calendar->Title = "Calendar";
         $calendar->ShowInMenus = false;
         $calendar->write();
         $calendar->publish('Stage', 'Live');
         $leaders = new ScoutGroupLeaders();
         $leaders->ParentID = $this->ID;
         $leaders->Title = "Leaders";
         $leaders->ShowInMenus = false;
         $leaders->write();
         $leaders->publish('Stage', 'Live');
     }
     $this->isInsert = false;
 }
 function onAfterWrite()
 {
     if ($this->ID) {
         $this->checkFolder();
     }
     parent::onAfterWrite();
 }
 /**
  * Updates the Image.ExifDate database column of image objects when page is saved
  *
  * @return void
  */
 function onAfterWrite()
 {
     parent::onAfterWrite();
     // update Image.ExifDate database fields of all images assigned to actual page if image sort option is set "4:ExifDate"
     // Todo: execute DB update on URL request instead page write to avoid timing issues when dealing with lots of big images
     if (cwsFolderGalleryPage_Controller::getImageSortOption() == "ExifDate") {
         cwsFolderGalleryImageExtension::writeExifDates($this->AlbumFolderID);
     }
 }
 function onAfterWrite()
 {
     parent::onAfterWrite();
     $path = Director::baseFolder() . "/.htaccess";
     $curr_data = @file($path);
     //Silverstripe is bad and should feel bad
     $page = DataObject::get_by_id('BlogPage', $this->ID, false);
     $extra = $page->BlogURL ? "RewriteCond %{REQUEST_URI} !^/" . $page->BlogURL : "";
     $new_file = array();
     // first remove any blog redirect already in the file
     $remove_keys = array();
     foreach ($curr_data as $key => $line) {
         if (trim($line) == "### Blog Redirect ###") {
             $remove_keys[] = $key;
             $remove_keys[] = $key + 1;
         }
     }
     foreach ($remove_keys as $key) {
         unset($curr_data[$key]);
     }
     $ss_line = 0;
     foreach ($curr_data as $line) {
         if (trim($line) == "### SILVERSTRIPE START ###") {
             $start = true;
         }
         if ($start && trim($line) == "RewriteCond %{REQUEST_FILENAME} !-f") {
             $inside = true;
         }
         if (trim($line) == "### SILVERSTRIPE END ###") {
             $inside = false;
         }
         if ($inside) {
             $new_file[] = trim("### Blog Redirect ###");
             $new_file[] = trim($extra);
             $inside = false;
         }
         $new_file[] = trim($line);
     }
     $h = @fopen($path, "w");
     fwrite($h, implode("\n", $new_file));
     @fclose($h);
 }
 public function onAfterWrite()
 {
     if ($this->isChanged('ID')) {
         $section = new MemberProfileFieldsSection();
         $section->ParentID = $this->ID;
         $section->write();
     }
     parent::onAfterWrite();
 }
Example #6
0
 /**
  * {@inheritdoc}
  *
  * Sets blog relationship on all categories and tags assigned to this post.
  */
 public function onAfterWrite()
 {
     parent::onAfterWrite();
     foreach ($this->Categories() as $category) {
         /**
          * @var BlogCategory $category
          */
         $category->BlogID = $this->ParentID;
         $category->write();
     }
     foreach ($this->Tags() as $tag) {
         /**
          * @var BlogTag $tag
          */
         $tag->BlogID = $this->ParentID;
         $tag->write();
     }
 }
 public function onAfterWrite()
 {
     Multisites::inst()->build();
     parent::onAfterWrite();
 }
Example #8
0
 public function onAfterWrite()
 {
     parent::onAfterWrite();
     // Don't do this stuff when we're publishing
     if (!$this->extension_instances['Versioned']->migratingVersion) {
         if ($this->isChanged('CopyContentFromID') && $this->CopyContentFromID != 0 && $this instanceof VirtualPage) {
             $this->updateImageTracking();
         }
     }
     // Check if page type has changed to a non-virtual page.
     // Caution: Relies on the fact that the current instance is still of the old page type.
     if ($this->isChanged('ClassName', 2)) {
         $changed = $this->getChangedFields();
         $classBefore = $changed['ClassName']['before'];
         $classAfter = $changed['ClassName']['after'];
         if ($classBefore != $classAfter) {
             // Remove all database rows for the old page type to avoid inconsistent data retrieval.
             // TODO This should apply to all page type changes, not only on VirtualPage - but needs
             // more comprehensive testing as its a destructive operation
             $removedTables = array_diff(ClassInfo::dataClassesFor($classBefore), ClassInfo::dataClassesFor($classAfter));
             if ($removedTables) {
                 foreach ($removedTables as $removedTable) {
                     // Note: *_versions records are left intact
                     foreach (array('', 'Live') as $stage) {
                         if ($stage) {
                             $removedTable = "{$removedTable}_{$stage}";
                         }
                         DB::prepared_query("DELETE FROM \"{$removedTable}\" WHERE \"ID\" = ?", array($this->ID));
                     }
                 }
             }
             // Also publish the change immediately to avoid inconsistent behaviour between
             // a non-virtual draft and a virtual live record (e.g. republishing the original record
             // shouldn't republish the - now unrelated - changes on the ex-VirtualPage draft).
             // Copies all stage fields to live as well.
             // @todo Update get_one to support parameterised queries
             $source = DataObject::get_by_id("SiteTree", $this->CopyContentFromID);
             $this->copyFrom($source);
             $this->publish('Stage', 'Live');
             // Change reference on instance (as well as removing the underlying database tables)
             $this->CopyContentFromID = 0;
         }
     }
 }
 function onAfterWrite()
 {
     parent::onAfterWrite();
     // Don't do this stuff when we're publishing
     if (!$this->extension_instances['Versioned']->migratingVersion) {
         if ($this->isChanged('CopyContentFromID') && $this->CopyContentFromID != 0 && $this instanceof VirtualPage) {
             $this->updateImageTracking();
         }
     }
 }
 /**
  * (non-PHPdoc)
  *
  * @see SiteTree::onBeforeWrite()
  */
 public function onAfterWrite()
 {
     parent::onAfterWrite();
     // Skip on publishing
     if (Versioned::get_live_stage() == Versioned::current_stage()) {
         return;
     }
     // Update the values of all fields added from editable field
     if ($this->ID && $this->many_many('Fields') && ($pageFields = $this->getEditableFields())) {
         foreach ($pageFields as $pageField) {
             // Set submitted value into the field
             $field = $pageField->getFormField();
             if (!$field) {
                 continue;
             }
             $field->setValue($this->{$pageField->Name});
             // Extra fields to be saved
             $value = $field->Value();
             $sort = $pageField->Sort;
             $group = $pageField->Group;
             // Clone the editable field object
             // Remove the current saved one
             $pageFields->remove($pageField);
             // Add the clone with the new extra data
             $pageFields->add($pageField, ['Value' => $value, 'Sort' => $sort, 'Group' => $group]);
         }
     }
 }
 function onAfterWrite()
 {
     parent::onAfterWrite();
     $this->RetrieveCampaigns();
 }
 public function onAfterWrite()
 {
     $this->addMemberAccountFields($this);
     parent::onAfterWrite();
 }
 function onAfterWrite()
 {
     parent::onAfterWrite();
     // Don't do this stuff when we're publishing
     if (!$this->extension_instances['Versioned']->migratingVersion) {
         if ($this->isChanged('CopyContentFromID') && $this->CopyContentFromID != 0 && $this instanceof VirtualPage) {
             $this->updateImageTracking();
         }
     }
     FormResponse::add("\$('Form_EditForm').reloadIfSetTo({$this->ID});", $this->ID . "_VirtualPage_onAfterWrite");
 }
 function onAfterWrite()
 {
     parent::onAfterWrite();
     if ($this->ImageID) {
         if ($normalImage = Image::get()->exclude(array("ClassName" => "Product_Image"))->byID($this->ImageID)) {
             $normalImage = $normalImage->newClassInstance("Product_Image");
             $normalImage->write();
         }
     }
 }
 function onAfterWrite()
 {
     parent::onAfterWrite();
     // Update TreePosition for all children
     $this->updateChildTreePositions(false);
 }
Example #16
0
 function onAfterWrite()
 {
     parent::onAfterWrite();
 }
 /**
  * Clear the cache if a new event is written
  */
 public function onAfterWrite()
 {
     $cache = SS_Cache::factory('calendar');
     $cache->remove('events');
     parent::onAfterWrite();
 }
    /**
     * Copy the original product options or generate the default product 
     * options
     * 
     * @see SiteTree::onAfterWrite()
     */
    function onAfterWrite()
    {
        parent::onAfterWrite();
        if ($this->firstWrite) {
            //TODO Make sure there is a StockLevel for this product by default
            $original = DataObject::get_by_id($this->class, $this->original['ID']);
            if ($original) {
                $images = $original->Images();
                $this->duplicateProductImages($images);
            }
        }
        //If the variation does not have a complete set of valid options, then disable it
        $variations = DataObject::get('Variation', "Variation.ProductID = " . $this->ID . " AND Variation.Status = 'Enabled'");
        if ($variations) {
            foreach ($variations as $variation) {
                if (!$variation->hasValidOptions()) {
                    $variation->Status = 'Disabled';
                    $variation->write();
                }
            }
        }
        $curr = Controller::curr();
        $request = $curr->getRequest();
        if ($request) {
            $categoryOrdering = $request->requestVar('CategoryOrder');
            if ($categoryOrdering && is_array($categoryOrdering)) {
                foreach ($categoryOrdering as $categoryID => $categoryOrder) {
                    $productID = $this->ID;
                    $query = <<<EOS
UPDATE "ProductCategory_Products" 
SET  "ProductOrder" =  '{$categoryOrder}' 
WHERE  "ProductCategory_Products"."ProductCategoryID" = {$categoryID} 
AND "ProductCategory_Products"."ProductID" = {$productID} 
EOS;
                    DB::query($query);
                }
            }
        }
    }