当前位置: 首页>>代码示例>>PHP>>正文


PHP DataObject::onBeforeWrite方法代码示例

本文整理汇总了PHP中SilverStripe\ORM\DataObject::onBeforeWrite方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObject::onBeforeWrite方法的具体用法?PHP DataObject::onBeforeWrite怎么用?PHP DataObject::onBeforeWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SilverStripe\ORM\DataObject的用法示例。


在下文中一共展示了DataObject::onBeforeWrite方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onBeforeWrite

 public function onBeforeWrite()
 {
     // Make sure ObjectClass refers to the base data class in the case of old or wrong code
     $this->ObjectClass = $this->getSchema()->baseDataClass($this->ObjectClass);
     parent::onBeforeWrite();
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:6,代码来源:ChangeSetItem.php

示例2: onBeforeWrite

 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // Just in case we've altered someone's permissions
     Permission::flush_permission_cache();
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:6,代码来源:Permission.php

示例3: onBeforeWrite

 /**
  * Event handler called before writing to the database.
  */
 public function onBeforeWrite()
 {
     if ($this->SetPassword) {
         $this->Password = $this->SetPassword;
     }
     // If a member with the same "unique identifier" already exists with a different ID, don't allow merging.
     // Note: This does not a full replacement for safeguards in the controller layer (e.g. in a registration form),
     // but rather a last line of defense against data inconsistencies.
     $identifierField = Member::config()->unique_identifier_field;
     if ($this->{$identifierField}) {
         // Note: Same logic as Member_Validator class
         $filter = array("\"{$identifierField}\"" => $this->{$identifierField});
         if ($this->ID) {
             $filter[] = array('"Member"."ID" <> ?' => $this->ID);
         }
         $existingRecord = DataObject::get_one('SilverStripe\\Security\\Member', $filter);
         if ($existingRecord) {
             throw new ValidationException(ValidationResult::create(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 email address', array('id' => $existingRecord->ID, 'name' => $identifierField, 'value' => $this->{$identifierField}))));
         }
     }
     // We don't send emails out on dev/tests sites to prevent accidentally spamming users.
     // However, if TestMailer is in use this isn't a risk.
     if ((Director::isLive() || Email::mailer() instanceof TestMailer) && $this->isChanged('Password') && $this->record['Password'] && $this->config()->notify_password_change) {
         /** @var Email $e */
         $e = Email::create();
         $e->setSubject(_t('Member.SUBJECTPASSWORDCHANGED', "Your password has been changed", 'Email subject'));
         $e->setTemplate('ChangePasswordEmail');
         $e->populateTemplate($this);
         $e->setTo($this->Email);
         $e->send();
     }
     // The test on $this->ID is used for when records are initially created.
     // Note that this only works with cleartext passwords, as we can't rehash
     // existing passwords.
     if (!$this->ID && $this->Password || $this->isChanged('Password')) {
         // Password was changed: encrypt the password according the settings
         $encryption_details = Security::encrypt_password($this->Password, $this->Salt, $this->PasswordEncryption ? $this->PasswordEncryption : Security::config()->password_encryption_algorithm, $this);
         // Overwrite the Password property with the hashed value
         $this->Password = $encryption_details['password'];
         $this->Salt = $encryption_details['salt'];
         $this->PasswordEncryption = $encryption_details['algorithm'];
         // If we haven't manually set a password expiry
         if (!$this->isChanged('PasswordExpiry')) {
             // then set it for us
             if (self::config()->password_expiry_days) {
                 $this->PasswordExpiry = date('Y-m-d', time() + 86400 * self::config()->password_expiry_days);
             } else {
                 $this->PasswordExpiry = null;
             }
         }
     }
     // save locale
     if (!$this->Locale) {
         $this->Locale = i18n::get_locale();
     }
     parent::onBeforeWrite();
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:60,代码来源:Member.php

示例4: onBeforeWrite

 /**
  * Make sure the file has a name
  */
 protected function onBeforeWrite()
 {
     // Set default owner
     if (!$this->isInDB() && !$this->OwnerID) {
         $this->OwnerID = Member::currentUserID();
     }
     // Set default name
     if (!$this->getField('Name')) {
         $this->Name = "new-" . strtolower($this->class);
     }
     // Propegate changes to the AssetStore and update the DBFile field
     $this->updateFilesystem();
     parent::onBeforeWrite();
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:17,代码来源:File.php

示例5: onBeforeWrite

 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // Only set code property when the group has a custom title, and no code exists.
     // The "Code" attribute is usually treated as a more permanent identifier than database IDs
     // in custom application logic, so can't be changed after its first set.
     if (!$this->Code && $this->Title != _t('SecurityAdmin.NEWGROUP', "New Group")) {
         $this->setCode($this->Title);
     }
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:10,代码来源:Group.php


注:本文中的SilverStripe\ORM\DataObject::onBeforeWrite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。