public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // only operate on staging content
     if (Versioned::current_stage() != 'Live') {
         if (strlen($this->owner->PublishOnDate)) {
             $changed = $this->owner->getChangedFields();
             $changed = isset($changed['PublishOnDate']);
             if ($changed && $this->owner->PublishJobID) {
                 if ($this->owner->PublishJob()->exists()) {
                     $this->owner->PublishJob()->delete();
                 }
                 $this->owner->PublishJobID = 0;
             }
             if (!$this->owner->PublishJobID && strtotime($this->owner->PublishOnDate) > time()) {
                 $job = new WorkflowPublishTargetJob($this->owner, 'publish');
                 $this->owner->PublishJobID = singleton('QueuedJobService')->queueJob($job, $this->owner->PublishOnDate);
             }
         }
         if (strlen($this->owner->UnPublishOnDate)) {
             $changed = $this->owner->getChangedFields();
             $changed = isset($changed['UnPublishOnDate']);
             if ($changed && $this->owner->UnPublishJobID) {
                 if ($this->owner->UnPublishJob()->exists()) {
                     $this->owner->UnPublishJob()->delete();
                 }
                 $this->owner->UnPublishJobID = 0;
             }
             if (!$this->owner->UnPublishJobID && strtotime($this->owner->UnPublishOnDate) > time()) {
                 $job = new WorkflowPublishTargetJob($this->owner, 'unpublish');
                 $this->owner->UnPublishJobID = singleton('QueuedJobService')->queueJob($job, $this->owner->UnPublishOnDate);
             }
         }
     }
 }
Esempio n. 2
0
 function __construct($searchFields)
 {
     if (is_array($searchFields)) {
         $this->searchFields = implode(',', $searchFields);
     } else {
         $this->searchFields = $searchFields;
     }
     parent::__construct();
 }
 /**
  * Construct a new Versioned object.
  * @var array $stages The different stages the versioned object can be.
  * The first stage is consiedered the 'default' stage, the last stage is
  * considered the 'live' stage.
  */
 function __construct($stages)
 {
     parent::__construct();
     if (!is_array($stages)) {
         $stages = func_get_args();
     }
     $this->stages = $stages;
     $this->defaultStage = reset($stages);
     $this->liveStage = array_pop($stages);
 }
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (isset($_GET["updatepayment"])) {
         DB::query("\n\t\t\t\tUPDATE \"Payment\"\n\t\t\t\tSET \"AmountAmount\" = \"Amount\"\n\t\t\t\tWHERE\n\t\t\t\t\t\"Amount\" > 0\n\t\t\t\t\tAND (\n\t\t\t\t\t\t\"AmountAmount\" IS NULL\n\t\t\t\t\t\tOR \"AmountAmount\" = 0\n\t\t\t\t\t)\n\t\t\t");
         $countAmountChanges = DB::affectedRows();
         if ($countAmountChanges) {
             DB::alteration_message("Updated Payment.Amount field to 2.4 - {$countAmountChanges} rows updated", "edited");
         }
         DB::query("\n\t\t\t\tUPDATE \"Payment\"\n\t\t\t\tSET \"AmountCurrency\" = \"Currency\"\n\t\t\t\tWHERE\n\t\t\t\t\t\"Currency\" <> ''\n\t\t\t\t\tAND \"Currency\" IS NOT NULL\n\t\t\t\t\tAND (\n\t\t\t\t\t\t\"AmountCurrency\" IS NULL\n\t\t\t\t\t\tOR \"AmountCurrency\" = ''\n\t\t\t\t\t)\n\t\t\t");
         $countCurrencyChanges = DB::affectedRows();
         if ($countCurrencyChanges) {
             DB::alteration_message("Updated Payment.Currency field to 2.4  - {$countCurrencyChanges} rows updated", "edited");
         }
         if ($countAmountChanges != $countCurrencyChanges) {
             DB::alteration_message("Potential error in Payment fields update to 2.4, please review data", "deleted");
         }
     }
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if ($this->owner->FirstExecution) {
         $changed = $this->owner->getChangedFields();
         $changed = isset($changed['FirstExecution']) || isset($changed['ExecuteEvery']) || isset($changed['ExecuteFree']);
         if ($changed && $this->owner->ScheduledJobID) {
             if ($this->owner->ScheduledJob()->exists()) {
                 $this->owner->ScheduledJob()->delete();
             }
             $this->owner->ScheduledJobID = 0;
         }
         if (!$this->owner->ScheduledJobID) {
             $job = new ScheduledExecutionJob($this->owner);
             $time = date('Y-m-d H:i:s');
             if ($this->owner->FirstExecution) {
                 $time = date('Y-m-d H:i:s', strtotime($this->owner->FirstExecution));
             }
             $this->owner->ScheduledJobID = singleton('QueuedJobService')->queueJob($job, $time);
         }
     }
 }
 public function canFrontEndEdit($member = null)
 {
     //we do this afterwards as we want to make sure that admins can edit all pages.
     if (!in_array($this->owner->class, self::$allowed_classes)) {
         return parent::canEdit($member);
     }
     if ($member instanceof Member) {
         $memberID = $member->ID;
     } else {
         if (is_numeric($member)) {
             $memberID = $member;
         } else {
             $memberID = Member::currentUserID();
         }
     }
     if ($memberID && Permission::checkMember($memberID, array("ADMIN", "SITETREE_EDIT_ALL", "SHOPADMIN"))) {
         return true;
     }
     if ($this->owner->ID) {
         if ($this->owner->CanEditType == 'LoggedInUsers') {
             return $memberID;
         } else {
             if ($this->owner->CanEditType == 'OnlyTheseUsers') {
                 $groups = DB::query("SELECT GroupID FROM SiteTree_EditorGroups WHERE SiteTreeID = {$this->owner->ID}")->column();
                 if ($memberID && count($groups) > 0) {
                     $groups = implode(',', $groups);
                     return DB::query("SELECT COUNT(*) FROM Group_Members WHERE MemberID = {$memberID} AND GroupID IN ({$groups})")->value();
                 }
             } elseif ($this->owner->ParentID) {
                 $parent = $this->owner->Parent();
                 if ($parent->exists()) {
                     return $parent->canFrontEndEdit($memberID);
                 }
             }
         }
     }
 }
 function onBeforeWrite()
 {
     if ($this->owner->Status == 'Paid' && $this->owner->NumSoldDone == 0) {
         $this->owner->NumSoldDone = 1;
         if ($orderItems = $this->owner->Items()) {
             foreach ($orderItems as $orderItem) {
                 if ($buyable = $orderItem->Buyable()) {
                     $oldNum = $buyable->NumberSold;
                     $newNum = $oldNum + $orderItem->Quantity;
                     $buyable->NumberSold = $newNum;
                     $buyable->write();
                     if ($buyable->ProductID > 0) {
                         if ($parent = DataObject::get_by_id("Product", $buyable->ProductID)) {
                             $parentOldNum = $parent->NumberSold;
                             $parent->NumberSold = $parentOldNum + $newNum;
                             $parent->write();
                         }
                     }
                 }
             }
         }
     }
     parent::onBeforeWrite();
 }
 /**
  * For folders, will need to add or remove the htaccess rules
  * Assumptions:
  *  - the folder exists (after write!)
  *  - no one else is trying to put htaccess rules here
  *  - (follows from above) existing htaccess file was put there by this module
  * @todo Add better support for existing htaccess files
  */
 function onAfterWrite()
 {
     parent::onAfterWrite();
     if ($this->owner instanceof Folder) {
         $htaccess = $this->owner->getFullPath() . SecureFileController::get_access_filename();
         if ($this->owner->Secured && !file_exists($htaccess)) {
             file_put_contents($htaccess, $this->htaccessContent());
         } elseif (!$this->owner->Secured && file_exists($htaccess)) {
             unlink($htaccess);
         }
     }
 }
	/**
	 * Intenionally unimplemented, use DataObject::write() with
	 * $writeComponents=true instead. The solution is not perfect,
	 * but there is no way to workaround Sapphire's component
	 * cache in this case.
	 */
	public function onAfterWrite() {
		parent::onAfterWrite();
	}
Esempio n. 10
0
 /**
  * Construct a new Translatable object.
  * @var array $translatableFields The different fields of the object that can be translated.
  */
 function __construct($translatableFields)
 {
     parent::__construct();
     if (!is_array($translatableFields)) {
         $translatableFields = func_get_args();
     }
     $this->translatableFields = $translatableFields;
 }
 /**
  * Prepare static variables before processing a {@link get_static} or {@link set_static}
  * call.
  */
 private static function prepare_statics($class)
 {
     // _cache_statics_prepared setting must come first to prevent infinite loops when we call
     // get_static below
     self::$_cache_statics_prepared[$class] = true;
     // load statics now for DataObject classes
     if (is_subclass_of($class, 'DataObject')) {
         $extensions = Object::uninherited_static($class, 'extensions');
         if ($extensions) {
             foreach ($extensions as $extension) {
                 DataObjectDecorator::load_extra_statics($class, $extension);
             }
         }
     }
 }
Esempio n. 12
0
 /**
  * Remove the record from the translation group mapping.
  */
 function onBeforeDelete()
 {
     // @todo Coupling to Versioned, we need to avoid removing
     // translation groups if records are just deleted from a stage
     // (="unpublished"). Ideally the translation group tables would
     // be specific to different Versioned changes, making this restriction unnecessary.
     // This will produce orphaned translation group records for SiteTree subclasses.
     if (!$this->owner->hasExtension('Versioned')) {
         $this->removeTranslationGroup();
     }
     parent::onBeforeDelete();
 }
Esempio n. 13
0
 /**
  * Remove an extension from a class.
  * Keep in mind that this won't revert any datamodel additions
  * of the extension at runtime, unless its used before the
  * schema building kicks in (in your _config.php).
  * Doesn't remove the extension from any {@link Object}
  * instances which are already created, but will have an
  * effect on new extensions.
  * Clears any previously created singletons through {@link singleton()}
  * to avoid side-effects from stale extension information.
  * 
  * @todo Add support for removing extensions with parameters
  *
  * @param string $class
  * @param string $extension Classname of an {@link Extension} subclass, without parameters
  */
 public static function remove_extension($class, $extension)
 {
     // unload statics now for DataObject classes
     if (ClassInfo::is_subclass_of($class, 'DataObject')) {
         if (!preg_match('/^([^(]*)/', $extension, $matches)) {
             user_error("Bad extension '{$extension}'", E_USER_WARNING);
         } else {
             $extensionClass = $matches[1];
             DataObjectDecorator::unload_extra_statics($class, $extensionClass);
         }
     }
     if (self::has_extension($class, $extension)) {
         self::set_static($class, 'extensions', array_diff(self::uninherited_static($class, 'extensions'), array($extension)));
     }
     // unset singletons to avoid side-effects
     global $_SINGLETONS;
     $_SINGLETONS = array();
     // unset some caches
     self::$cached_statics[$class]['extensions'] = null;
     $subclasses = ClassInfo::subclassesFor($class);
     $subclasses[] = $class;
     if ($subclasses) {
         foreach ($subclasses as $subclass) {
             unset(self::$classes_constructed[$subclass]);
             unset(self::$extra_methods[$subclass]);
         }
     }
 }
 public function onAfterWrite()
 {
     parent::onAfterWrite();
     self::add_members_to_customer_group();
 }
 function __construct($moderationScore = null, $spamScore = null)
 {
     parent::__construct();
     $this->RequiredModerationScore = $moderationScore ? $moderationScore : $this->stat('default_moderation_score');
     $this->RequiredSpamScore = $spamScore ? $spamScore : $this->stat('default_spam_score');
 }
 /**
  * standard SS method
  * try to finalise order if payment has been made.
  */
 function onAfterWrite()
 {
     parent::onAfterWrite();
     $order = $this->owner->PaidObject();
     if ($order && $order instanceof Order && $order->IsSubmitted()) {
         $order->tryToFinaliseOrder();
     }
 }
	public function onBeforeWrite() {
		parent::onBeforeWrite();
		foreach ($this->getEnforcedValues() as $field => $value)
			$this->owner->$field = $value;
	}
 function onAfterDelete()
 {
     parent::onAfterDelete();
     $this->cleaningUpVariationData();
 }
Esempio n. 19
0
 /**
  * Adds methods from the extensions.
  * Called by Object::__construct() once per class.
  */
 function defineMethods()
 {
     if ($this->class == 'DataObject') {
         return;
     }
     parent::defineMethods();
     // Define the extra db fields - this is only necessary for extensions added in the
     // class definition.  Object::add_extension() will call this at definition time for
     // those objects, which is a better mechanism.  Perhaps extensions defined inside the
     // class def can somehow be applied at definiton time also?
     if ($this->extension_instances) {
         foreach ($this->extension_instances as $i => $instance) {
             if (!$instance->class) {
                 $class = get_class($instance);
                 user_error("DataObject::defineMethods(): Please ensure {$class}::__construct() calls parent::__construct()", E_USER_ERROR);
             }
             DataObjectDecorator::load_extra_statics($this->class, $instance->class);
         }
     }
     // Set up accessors for joined items
     if ($manyMany = $this->many_many()) {
         foreach ($manyMany as $relationship => $class) {
             $this->addWrapperMethod($relationship, 'getManyManyComponents');
         }
     }
     if ($hasMany = $this->has_many()) {
         foreach ($hasMany as $relationship => $class) {
             $this->addWrapperMethod($relationship, 'getComponents');
         }
     }
     if ($hasOne = $this->has_one()) {
         foreach ($hasOne as $relationship => $class) {
             $this->addWrapperMethod($relationship, 'getComponent');
         }
     }
 }
 /**
  * Prepare static variables before processing a {@link get_static} or {@link set_static}
  * call.
  */
 private static function prepare_statics($class)
 {
     // _cache_statics_prepared setting must come first to prevent infinite loops when we call
     // get_static below
     self::$_cache_statics_prepared[$class] = true;
     // load statics now for DataObject classes
     if (is_subclass_of($class, 'DataObject')) {
         $extensions = Object::uninherited_static($class, 'extensions');
         if ($extensions) {
             foreach ($extensions as $extension) {
                 $extensionClass = $extension;
                 if (preg_match('/^([^(]*)/', $extension, $matches)) {
                     $extensionClass = $matches[1];
                 }
                 if (is_subclass_of($extensionClass, 'DataObjectDecorator')) {
                     DataObjectDecorator::load_extra_statics($class, $extension);
                 } else {
                     user_error("{$extensionClass} cannot be applied to {$class} without being a DataObjectDecorator", E_USER_ERROR);
                 }
             }
         }
     }
 }
 /**
  * Removes the object from the search index after it has been deleted.
  */
 function onAfterDelete()
 {
     ZendSearchLuceneWrapper::delete($this->owner);
     parent::onAfterDelete();
 }
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $bt = defined('DB::USE_ANSI_SQL') ? '"' : '`';
     $update = array();
     $siteConfig = DataObject::get_one('SiteConfig');
     $folder = Folder::findOrMake(self::get_folder_name());
     if ($siteConfig && $folder) {
         $fullArray = self::get_images_to_replace();
         //copying ....
         if ($fullArray) {
             foreach ($fullArray as $key => $array) {
                 $className = $array["ClassName"];
                 $fieldName = $array["FieldName"] . "ID";
                 if (class_exists($className)) {
                     $dataObject = singleton($className);
                     $dbFieldName = $array["DBFieldName"];
                     $fileName = basename($array["CopyFromPath"]);
                     $fromLocationLong = Director::baseFolder() . '/' . $array["CopyFromPath"];
                     $toLocationShort = "assets/" . self::get_folder_name() . "/{$fileName}";
                     $toLocationLong = Director::baseFolder() . '/' . $toLocationShort;
                     $image = DataObject::get_one('Image', "Filename='{$toLocationShort}' AND ParentID = " . $folder->ID);
                     if (!$image) {
                         if (!file_exists($toLocationLong)) {
                             copy($fromLocationLong, $toLocationLong);
                         }
                         $image = new Image();
                         $image->ParentID = $folder->ID;
                         $image->FileName = $toLocationShort;
                         $image->setName($fileName);
                         $image->write();
                     } elseif (!$image && file_exists($toLocationLong)) {
                         debug::show("need to update files");
                     }
                     if ($image && $image->ID) {
                         if (!$siteConfig->{$dbFieldName}) {
                             $siteConfig->{$dbFieldName} = $image->ID;
                             $update[] = "created placeholder image for {$key}";
                         }
                         $updateSQL = " UPDATE {$bt}" . $className . "{$bt}";
                         if (isset($_GET["removeplaceholderimages"])) {
                             $setSQL = " SET {$bt}" . $fieldName . "{$bt} = 0";
                             $whereSQL = " WHERE {$bt}" . $fieldName . "{$bt}  = " . $image->ID;
                             DB::alteration_message("removing " . $className . "." . $fieldName . " placeholder images", 'deleted');
                         } else {
                             DB::alteration_message("adding " . $className . "." . $fieldName . " placeholder images", 'created');
                             $setSQL = " SET {$bt}" . $fieldName . "{$bt} = " . $image->ID;
                             if (!isset($_GET["forceplaceholder"])) {
                                 $whereSQL = " WHERE {$bt}" . $fieldName . "{$bt} IS NULL OR {$bt}" . $fieldName . "{$bt} = 0";
                             } else {
                                 $whereSQL = '';
                             }
                         }
                         $sql = $updateSQL . $setSQL . $whereSQL;
                         DB::query($sql);
                         $versioningPresent = false;
                         $array = $dataObject->stat('extensions');
                         if (is_array($array) && count($array)) {
                             if (in_array("Versioned('Stage', 'Live')", $array)) {
                                 $versioningPresent = true;
                             }
                         }
                         if ($dataObject->stat('versioning')) {
                             $versioningPresent = true;
                         }
                         if ($versioningPresent) {
                             $sql = str_replace("{$bt}{$className}{$bt}", "{$bt}{$className}_Live{$bt}", $sql);
                             DB::query($sql);
                         }
                     } else {
                         debug::show("could not create image!" . print_r($array));
                     }
                 } else {
                     debug::show("bad classname reference " . $className);
                 }
             }
         }
         if (count($update)) {
             $siteConfig->write();
             DB::alteration_message($siteConfig->ClassName . " created/updated: " . implode(" --- ", $update), 'created');
         }
     } elseif (!$folder) {
         debug::show("COULD NOT CREATE FOLDER: " . self::get_folder_name());
     }
 }