/** * Update the tagging to reflect the change, allowing searchable content. */ public function onBeforeWrite() { parent::onBeforeWrite(); // Determine whether consolidated tags are found in the existing relationships. $types = array(); foreach (singleton('FusionService')->getFusionTagTypes() as $type => $field) { $types[$type] = $type; } $types = array_intersect($this->owner->many_many(), $types); if (empty($types)) { // There are no consolidated tags found, therefore update the tagging based on the fusion tags. $tagging = array(); foreach ($this->owner->FusionTags() as $tag) { $tagging[] = $tag->Title; } } else { // Empty the fusion tags to begin. $this->owner->FusionTags()->removeAll(); // There are consolidated tags found, therefore update the tagging based on these. $tagging = array(); foreach ($types as $relationship => $type) { foreach ($this->owner->{$relationship}() as $tag) { // Update both the fusion tags and tagging. $fusion = $tag->FusionTag(); $this->owner->FusionTags()->add($fusion); $tagging[] = $fusion->Title; } } } $this->owner->Tagging = implode(' ', $tagging); }
/** * Generate a URL Segement before the data object gets written */ public function onBeforeWrite() { if ($this->owner->Title) { $this->owner->URLSegment = $this->generateURLSegment($this->owner->Title); } parent::onBeforeWrite(); }
public function onBeforeWrite() { parent::onBeforeWrite(); // Load the significant_fields and check to see if they have changed if they have record the current DateTime $significant = Config::inst()->get($this->owner->Classname, 'significant_fields'); $isSignicantChange = $this->owner->isSignificantChange; if (isset($significant) && !$isSignicantChange) { $significant = array_combine($significant, $significant); //If the owner object or an extension of it implements getSignificantChange call it instead of testing here if ($this->owner->hasMethod('getSignificantChange') && $this->owner->getSignificantChange()) { //Set LastSignificantChange to now $this->owner->LastSignificantChange = date(DateTime::ATOM); } else { $changes = $this->owner->getChangedFields(true, 2); //A simple interesect of the keys gives us whether a change has occurred if (count($changes) && count(array_intersect_key($changes, $significant))) { //Set LastSignificantChange to now $this->owner->LastSignificantChange = date(DateTime::ATOM); } } //If we don't have any significant changes leave the field alone as a previous edit may have been //significant. } else { if ($this->owner->isInDB()) { $this->owner->LastSignificantChange = NULL; } } }
/** * Update the corresponding vanity mapping. */ public function onBeforeWrite() { parent::onBeforeWrite(); // Retrieve the vanity mapping URL, where this is only possible using the POST variable. $vanityURL = is_null($URL = Controller::curr()->getRequest()->postVar('VanityURL')) ? $this->owner->VanityMapping()->MappedLink : $URL; $mappingExists = $this->owner->VanityMapping()->exists(); // Determine whether the vanity mapping URL has been updated. if ($vanityURL && $mappingExists) { if ($this->owner->VanityMapping()->MappedLink !== $vanityURL) { // Update the corresponding vanity mapping. $this->owner->VanityMapping()->MappedLink = $vanityURL; $this->owner->VanityMapping()->write(); } } else { if ($vanityURL) { // Instantiate the vanity mapping. $mapping = singleton('MisdirectionService')->createPageMapping($vanityURL, $this->owner->ID, 2); $this->owner->VanityMappingID = $mapping->ID; } else { if ($mappingExists) { // Remove the corresponding vanity mapping. $this->owner->VanityMapping()->delete(); } } } }
function onBeforeWrite() { if ($this->owner->Status == 'Paid' && $this->owner->StockHasBeenCalculated == 0) { $this->owner->StockHasBeenCalculated = 1; if ($orderItems = $this->owner->Items()) { foreach ($orderItems as $orderItem) { if ($buyable = $orderItem->Buyable()) { if ($buyable->UnlimitedStock == 0) { $oldNum = $buyable->Stock; $newNum = $oldNum - $orderItem->Quantity; $buyable->Stock = $newNum; $buyable->write(); } } } } } if ($this->owner->Status == 'AdminCancelled' && $this->owner->StockHasBeenCalculated == 1 || $this->owner->Status == 'MemberCancelled' && $this->owner->StockHasBeenCalculated == 1) { if ($orderItems = $this->owner->Items()) { foreach ($orderItems as $orderItem) { if ($buyable = $orderItem->Buyable()) { $oldNum = $buyable->Stock; $newNum = $oldNum + $orderItem->Quantity; $buyable->Stock = $newNum; $buyable->write(); } } } } parent::onBeforeWrite(); }
public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->owner->SiteID) { $this->owner->SiteID = Multisites::inst()->getActiveSite()->ID; } }
/** * Set up defaults for fields */ public function onBeforeWrite() { /** ========================================= * @var TwitterSiteConfigExtension $siteConfig ===========================================*/ parent::onBeforeWrite(); $siteConfig = SiteConfig::current_site_config(); if ($this->owner->exists()) { if ($this->owner->isChanged('Content') && !$this->owner->TwitterDescription) { $this->owner->setField('TwitterDescription', $this->owner->dbObject('Content')->Summary(50)); } if ($this->owner->isChanged('Title') && !$this->owner->TwitterTitle) { $this->owner->setField('TwitterTitle', $this->owner->Title); } if (!$this->owner->TwitterSite) { $this->owner->setField('TwitterSite', $siteConfig->DefaultTwitterHandle); } if (!$this->owner->TwitterCreator) { $this->owner->setField('TwitterCreator', $siteConfig->DefaultTwitterHandle); } if (!$this->owner->TwitterImageID) { $this->owner->setField('TwitterImageID', $siteConfig->DefaultTwitterImageID); } } if (!$this->owner->TwitterTitle) { $this->owner->setField('TwitterTitle', $this->owner->Title); } if (!$this->owner->TwitterDescription) { $this->owner->setField('TwitterDescription', $this->owner->dbObject('Content')->Summary(50)); } }
/** * Set URLSegment to be unique on write */ public function onBeforeWrite() { parent::onBeforeWrite(); $defaults = $this->owner->config()->defaults; $URLSegment = $this->owner->URLSegment; // If there is no URLSegment set, generate one from Title if ((!$URLSegment || $URLSegment == $defaults['URLSegment']) && $this->owner->Title != $defaults['Title']) { $URLSegment = $this->generateURLSegment($this->owner->Title); } else { if ($this->owner->isChanged('URLSegment')) { // Make sure the URLSegment is valid for use in a URL $segment = preg_replace('/[^A-Za-z0-9]+/', '-', $this->owner->URLSegment); $segment = preg_replace('/-+/', '-', $segment); // If after sanitising there is no URLSegment, give it a reasonable default if (!$segment) { $segment = $this->fallbackUrl(); } $URLSegment = $segment; } } // Ensure that this object has a non-conflicting URLSegment value. $count = 2; $ID = $this->owner->ID; while ($this->lookForExistingURLSegment($URLSegment, $ID)) { $URLSegment = preg_replace('/-[0-9]+$/', null, $URLSegment) . '-' . $count; $count++; } $this->owner->URLSegment = $URLSegment; }
public function onBeforeWrite() { if (Config::inst()->get(__CLASS__, 'flush_on_change') && ($this->owner->isChanged('FocusX') || $this->owner->isChanged('FocusY'))) { $this->owner->deleteFormattedImages(); } parent::onBeforeWrite(); }
public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->owner->ID && !$this->owner->PublicationDate) { $this->owner->PublicationDate = date("Y-m-d H:i:s"); } }
/** * Set VerificationString if not set * If not verified log out user and display message. */ function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->owner->VerificationString) { $this->owner->VerificationString = MD5(rand()); } if (!$this->owner->Verified) { if (!$this->owner->VerificationEmailSent) { if (!self::$hasOnBeforeWrite) { self::$hasOnBeforeWrite = true; $this->owner->sendemail($this->owner, false); } } if (Member::currentUserID() && $this->owner->Email == Member::currentUser()->Email) { Security::logout(false); if (!is_null(Controller::redirectedTo())) { $messageSet = array('default' => _t('EmailVerifiedMember.EMAILVERIFY', 'Please verify your email address by clicking on the link in the email before logging in.')); } Session::set("Security.Message.type", 'bad'); Security::permissionFailure(Controller::curr(), $messageSet); } else { return; } } else { return; } }
function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->owner->ID && $this->owner->ClassName == 'ErrorPage') { $this->owner->ShowInSiteMap = 0; } }
function onBeforeWrite() { if (!$this->owner->ID && !$this->owner->SubsiteID && Subsite::currentSubsiteID()) { $this->owner->SubsiteID = Subsite::currentSubsiteID(); } parent::onBeforeWrite(); }
public function onBeforeWrite() { parent::onBeforeWrite(); // Create the base folder if (!$this->owner->BaseFolder && $this->owner->Title) { $filter = new FileNameFilter(); $this->owner->BaseFolder = $filter->filter($this->owner->getTitle()); $this->owner->BaseFolder = str_replace(' ', '', ucwords(str_replace('-', ' ', $this->owner->BaseFolder))); } // If name has changed, rename existing groups $changes = $this->owner->getChangedFields(); if (isset($changes['Title']) && !empty($changes['Title']['before'])) { $filter = new URLSegmentFilter(); $groupName = $this->getAdministratorGroupName($changes['Title']['before']); $group = self::getGroupByName($groupName); if ($group) { $group->Title = $this->getAdministratorGroupName($changes['Title']['after']); $group->Code = $filter->filter($group->Title); $group->write(); } $membersGroupName = $this->getMembersGroupName($changes['Title']['before']); $membersGroup = self::getGroupByName($membersGroupName); if ($membersGroup) { $membersGroup->Title = $this->getMembersGroupName($changes['Title']['after']); $membersGroup->Code = $filter->filter($membersGroup->Title); $membersGroup->write(); } } }
/** * Write the Color field to get the dominant color if not set */ public function onBeforeWrite() { if ($this->owner->getField('Color') === null) { $this->owner->Color = $this->dominantColor(); } parent::onBeforeWrite(); }
public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->owner->ScheduledTitle) { $this->owner->ScheduledTitle = $this->owner->Title; } if ($this->owner->FirstGeneration) { $changed = $this->owner->getChangedFields(); $changed = false || isset($changed['FirstGeneration']) || isset($changed['RegenerateEvery']) || isset($changed['RegenerateFree']); if ($changed && $this->owner->ScheduledJobID) { if ($this->owner->ScheduledJob()->ID) { $this->owner->ScheduledJob()->delete(); } $this->owner->ScheduledJobID = 0; } if (!$this->owner->ScheduledJobID) { $job = new ScheduledReportJob($this->owner); $time = date('Y-m-d H:i:s'); if ($this->owner->FirstGeneration) { $time = date('Y-m-d H:i:s', strtotime($this->owner->FirstGeneration)); } $this->owner->ScheduledJobID = singleton('QueuedJobService')->queueJob($job, $time); } } }
public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->owner->Locale) { $this->owner->Locale = Translatable::get_current_locale(); } }
public function onBeforeWrite() { // init parent parent::onBeforeWrite(); // owner $owner = $this->owner; // this will NOT trigger during requireDefaultRecords(), to prevent setting blank values // @todo Is this the optimal solution ?? if ($owner->OpenGraphType != null) { // $data = json_decode($owner->OpenGraphData, true); // $data['og:type'] = $owner->OpenGraphType; // prevent clearing of existing values if ($data['og:type'] !== 'off') { // URL $data['og:url'] = $owner->OpenGraphURL; // site name $data['og:site_name'] = $owner->OpenGraphSiteName; // title $data['og:title'] = $owner->OpenGraphTitle; // description $data['og:description'] = $owner->OpenGraphDescription; } // $owner->OpenGraphData = json_encode($data); } }
public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->owner->ID && !$this->owner->SubsiteID) { $this->owner->SubsiteID = Subsite::currentSubsiteID(); } }
/** * Decorate the Member object to ghost the user if suspected of being a spammer. */ public function onBeforeWrite() { parent::onBeforeWrite(); // we only want to run this if any of the fields to check have been modified. $shouldRun = false; foreach ($this->owner->config()->fields_to_check as $field) { if ($this->owner->isChanged($field)) { $shouldRun = true; break; } } if (!$shouldRun) { return; } $spam_needles = SuspendSpammerKeyword::get(); if ($spam_needles) { $spam_needles = $spam_needles->map()->toArray(); } else { $spam_needles = array(); } //if anything matches do something about it to stop the spam registration. if (0 < count(array_intersect($this->spamHaystack(), $spam_needles))) { //Ghost a spammer. $this->owner->ForumStatus = 'Ghost'; //Email the admin if (Config::inst()->get('SuspendSpammerEmail', 'enable_email') && !$this->owner->ID) { $body = "<h1>Suspected Spammer Registration</h1>\n\t\t\t\t<ul>\n\t\t\t\t<li>Email: " . $this->owner->Email . "</li>"; foreach ($this->owner->config()->fields_to_check as $field) { $body .= "<li>" . $field . ": " . $this->owner->{$field} . "</li>"; } $body .= "</ul>"; SuspendSpammerEmail::create($body)->send(); } } }
public function onBeforeWrite() { parent::onBeforeWrite(); // immediately unindex any stuff that shouldn't be show in search if ($this->owner->isChanged('ShowInSearch') && !$this->owner->ShowInSearch) { $this->searchService->unindex($this->owner); } }
/** * Automatically sets PublishDate to now, if is empty. */ public function onBeforeWrite() { if ($this->owner->ID) { if ($this->owner->PublishDate == '') { $this->owner->PublishDate = date('Y-m-d H:i:s', strtotime('now')); } } parent::onBeforeWrite(); }
public function onBeforeWrite() { //Update individual focus points if ($this->owner->FocusXY) { $coords = FocusPointField::fieldValueToSourceCoords($this->owner->FocusXY); $this->owner->FocusX = $coords[0]; $this->owner->FocusY = $coords[1]; } parent::onBeforeWrite(); }
public function onBeforeWrite() { parent::onBeforeWrite(); if ($this->owner->isInDB()) { $this->dataChangeTrackService->track($this->owner, $this->changeType); } else { $this->isNewObject = TRUE; $this->changeType = 'New'; } }
/** * Set VerificationString if not set, and send verification email if not sent. */ public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->owner->VerificationString) { $verification_string = md5(uniqid($this->owner->Email, true)); $this->owner->VerificationString = $verification_string; } if (!$this->owner->Verified && !$this->owner->VerificationEmailSent) { $this->owner->VerificationEmailSent = $this->owner->sendVerificationEmail(); } }
function onBeforeWrite() { parent::onBeforeWrite(); // strip the rest of the code and get the id. This stop accidental html structural breaks preg_match("/scripts\\/(\\d{4}\\/\\d{4})\\.js/i", $this->owner->CrazyEgg, $match); if (isset($match[0])) { $CrazyEggID = istr_replace('scripts/', '', $match[0]); $CrazyEggID = istr_replace('.js', '', $CrazyEggID); $this->owner->CrazyEgg = $CrazyEggID; } }
/** * Ensures config defaults are enforced on write */ public function onBeforeWrite() { parent::onBeforeWrite(); if (empty($this->owner->DefaultPreviewMode)) { $this->owner->DefaultPreviewMode = Config::inst()->get('UserPreviewPreference', 'DefaultMode'); } //If changed ensure their is a session message if ($this->owner->isChanged('DefaultPreviewMode')) { Session::set('ShowPreviewSettingChangeReload', true); $this->isSaving = true; } }
public function onBeforeWrite() { parent::onBeforeWrite(); if ($this->owner->exists()) { if ($this->owner->isChanged('Content') && !$this->owner->MetaDescription) { $this->owner->setField('MetaDescription', $this->owner->dbObject('Content')->Summary(25)); } if ($this->owner->isChanged('Title') && !$this->owner->SEOTitle) { $this->owner->setField('SEOTitle', $this->owner->Title); } } }
public function onBeforeWrite() { if ($username = $this->owner->Username) { $identifierField = 'Username'; $id = $this->owner->ID; $idClause = $id ? sprintf(" AND \"Member\".\"ID\" <> %d", (int) $id) : ''; $existingRecord = DataObject::get_one('Member', sprintf("\"%s\" = '%s' %s", $identifierField, Convert::raw2sql($username), $idClause)); if ($existingRecord) { throw new ValidationException(new ValidationResult(false, _t('Member.ValidationIdentifierFailed', 'Can\'t overwrite existing member #{id} with identical identifier ({name} = {value})', 'Values in brackets show "fieldname = value", usually denoting an existing username', array('id' => $existingRecord->ID, 'name' => $identifierField, 'value' => $username)))); } } parent::onBeforeWrite(); }
public function onBeforeWrite() { parent::onBeforeWrite(); $dbFields = Config::inst()->get($this->owner->ClassName, 'db', Config::UNINHERITED); $changedFields = is_array($this->owner->getChangedFields()) ? $this->owner->getChangedFields() : array(); if (is_array($dbFields)) { foreach ($dbFields as $dbFieldName => $dbFieldType) { $field = $this->owner->dbObject($dbFieldName); if ($this->shouldEncrypt($changedFields, $dbFieldName, $field)) { $field->prepValueForDB($this->owner->{$dbFieldName}); } } } }