/**
  * @throws ValidationException
  * @throws null
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     /**
      * Add default site admin group if none with
      * permission code SITE_ADMIN exists
      *
      * @var Group $siteAdminGroup
      */
     $siteAdminGroups = DataObject::get('Group')->filter(array('Code' => 'site-administrators'));
     if (!$siteAdminGroups->count()) {
         $siteAdminGroup = Group::create();
         $siteAdminGroup->Code = 'site-administrators';
         $siteAdminGroup->Title = _t('BoilerplateGroupExtension.SiteAdminGroupTitle', 'Site Administrators');
         $siteAdminGroup->Sort = 0;
         $siteAdminGroup->write();
         /** Default CMS permissions */
         Permission::grant($siteAdminGroup->ID, 'CMS_ACCESS_LeftAndMain');
         Permission::grant($siteAdminGroup->ID, 'SITETREE_VIEW_ALL');
         Permission::grant($siteAdminGroup->ID, 'SITETREE_EDIT_ALL');
         Permission::grant($siteAdminGroup->ID, 'SITETREE_REORGANISE');
         Permission::grant($siteAdminGroup->ID, 'VIEW_DRAFT_CONTENT');
         Permission::grant($siteAdminGroup->ID, 'SITETREE_GRANT_ACCESS');
         Permission::grant($siteAdminGroup->ID, 'EDIT_SITECONFIG');
     }
 }
コード例 #2
0
 function onBeforeWrite()
 {
     if (!$this->owner->ID && !$this->owner->SubsiteID && Subsite::currentSubsiteID()) {
         $this->owner->SubsiteID = Subsite::currentSubsiteID();
     }
     parent::onBeforeWrite();
 }
コード例 #3
0
 public function updateCMSFields(\FieldList $fields)
 {
     if (!Permission::check('ADMIN')) {
         Requirements::css(HIDE_HISTORY_BASE . '/css/hide-history.css');
     }
     parent::updateCMSFields($fields);
 }
コード例 #4
0
 /**
  * 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;
     }
 }
コード例 #5
0
 public function onAfterWrite()
 {
     parent::onAfterWrite();
     $AvailableTypes = $this->AvailableSectionTypes();
     foreach ($AvailableTypes as $key => $value) {
         $ClassName = $AvailableTypes[$key]['classname'];
         if ($AvailableTypes[$key]['presets'] !== null) {
             foreach ($AvailableTypes[$key]['presets'] as $AdminTitle => $ShareStatus) {
                 $Section = $this->owner->Sections()->filter(array('ClassName' => $ClassName, 'UniqueConfigTitle' => $AdminTitle));
                 if ($Section->Count()) {
                     continue;
                 }
                 $ExistingSection = $ClassName::get()->filter(array('ClassName' => $ClassName, 'UniqueConfigTitle' => $AdminTitle))->first();
                 if ($ExistingSection && $ShareStatus == 'shared') {
                     $this->owner->Sections()->add($ExistingSection);
                 } else {
                     $newSection = $ClassName::create();
                     $newSection->UniqueConfigTitle = $AdminTitle;
                     $newSection->AdminTitle = $AdminTitle;
                     $newSection->Public = true;
                     $newSection->Write();
                     $this->owner->Sections()->add($newSection);
                 }
             }
         }
     }
 }
コード例 #6
0
 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();
 }
コード例 #7
0
 /**
  * Override to avoid Dup groups titles and slugs
  */
 function onAfterWrite()
 {
     parent::onAfterWrite();
     $exits_group = false;
     $suffix = 1;
     //get original values
     $original_code = $this->owner->Code;
     $original_title = $this->owner->Title;
     //iterate until we get an unique slug and title
     while (!$exits_group) {
         $new_code = $this->owner->Code;
         $new_title = $this->owner->Title;
         $id = $this->owner->ID;
         //check if group already exists...
         $count = DB::query(" SELECT COUNT(*) FROM \"Group\" WHERE Code ='{$new_code}' AND ID <> {$id}")->value();
         if ($count) {
             //if exists , rename it
             $this->owner->Code = $original_code . '-' . $suffix;
             $this->owner->Title = $original_title . ' ' . $suffix;
         } else {
             DB::query("UPDATE \"Group\" SET Code= '{$new_code}', Title = '{$new_title}' WHERE ID = {$id} ");
             $exits_group = true;
         }
         ++$suffix;
     }
 }
コード例 #8
0
 /**
  * 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();
 }
コード例 #9
0
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     // Add default author group if no other group exists
     $frontend_group = Group::get()->filter("Code", "users-frontend");
     if (!$frontend_group->exists()) {
         $frontend_group = new Group();
         $frontend_group->Code = 'users-frontend';
         $frontend_group->Title = "Frontend Users";
         $frontend_group->Sort = 1;
         $frontend_group->write();
         Permission::grant($frontend_group->ID, 'USERS_MANAGE_ACCOUNT');
         DB::alteration_message('Front end users group created', 'created');
     }
     // Add a verified users group (only used if we turn on
     // verification)
     $verify_group = Group::get()->filter("Code", "users-verified");
     if (!$verify_group->exists()) {
         $verify_group = new Group();
         $verify_group->Code = 'users-verified';
         $verify_group->Title = "Verified Users";
         $verify_group->Sort = 1;
         $verify_group->write();
         Permission::grant($verify_group->ID, 'USERS_VERIFIED');
         DB::alteration_message('Verified users group created', 'created');
     }
 }
コード例 #10
0
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->owner->Locale) {
         $this->owner->Locale = Translatable::get_current_locale();
     }
 }
 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);
         }
     }
 }
コード例 #12
0
 /**
  * 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;
 }
コード例 #13
0
 /**
  * Remove the administrators group from the possible parent group
  * 
  * @todo this check should be done in core code, since the dropdown can be simply 
  *				crafted for injecting administrators group ID
  * @param \FieldList $fields
  */
 public function updateCMSFields(\FieldList $fields)
 {
     parent::updateCMSFields($fields);
     /* @var $parentID DropdownField */
     $parentID = $fields->fieldByName('Root.Members.ParentID');
     $parentID->setDisabledItems(array(DataObject::get_one('Group', "Code='administrators'")->ID));
 }
コード例 #14
0
 public function setOwner($owner, $ownerBaseClass = null)
 {
     if (!$this->hasSetRelationForHidingFromFieldLists) {
         static::$connected_relations[] = get_class($owner);
     }
     return parent::setOwner($owner, $ownerBaseClass);
 }
コード例 #15
0
 /**
  *	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);
 }
コード例 #16
0
ファイル: Addressable.php プロジェクト: 8secs/cocina
 public function __construct()
 {
     $this->allowedStates = self::$allowed_states;
     $this->allowedCountries = self::$allowed_countries;
     $this->postcodeRegex = self::$postcode_regex;
     parent::__construct();
 }
 /**
  * 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();
     // 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;
         }
     }
 }
コード例 #19
0
 /**
  * Creates WidgetArea DataObjects in not aleready done.
  */
 public function onAfterWrite()
 {
     parent::onAfterWrite();
     $has_one = $this->owner->has_one();
     // Loop over each WidgetArea
     foreach ($has_one as $name => $class) {
         if ($class == 'WidgetArea') {
             // Create the WidgetArea if it not exist
             $dbName = $name . 'ID';
             // Can't use $this->owner->$name()->ID since it doesn't
             // work with DataObjects, it works just with Pages. SS bug?
             if ($this->owner->{$dbName} == 0) {
                 $wa = new WidgetArea();
                 $wa->write();
                 $this->owner->{$dbName} = $wa->ID;
                 if ($this->owner->hasExtension('Versioned')) {
                     $this->owner->writeWithoutVersion();
                 } else {
                     $dbg = $this->owner->{$name}();
                     $this->owner->write();
                 }
             }
         }
     }
 }
コード例 #20
0
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->owner->ID && !$this->owner->SubsiteID) {
         $this->owner->SubsiteID = Subsite::currentSubsiteID();
     }
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->owner->SiteID) {
         $this->owner->SiteID = Multisites::inst()->getActiveSite()->ID;
     }
 }
コード例 #22
0
 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()
 {
     // 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);
     }
 }
コード例 #24
0
 public function onAfterWrite()
 {
     parent::onAfterWrite();
     //create supported versions for not versioned components
     $supported_components = $this->owner->OpenStackComponents();
     if ($supported_components && count($supported_components) > 0) {
         $non_versioned_components = array();
         foreach ($supported_components as $component) {
             if (!$component->getSupportsVersioning()) {
                 //crete dumb version
                 array_push($non_versioned_components, $component->getIdentifier());
                 $old = $this->owner->SupportedApiVersions(" OpenStackComponentID = {$component->getIdentifier()} AND ApiVersionID = 0 ");
                 if (count($old) == 0) {
                     $new_supported_version = new OpenStackReleaseSupportedApiVersion();
                     $new_supported_version->OpenStackComponentID = $component->getIdentifier();
                     $new_supported_version->ReleaseID = $this->owner->getIdentifier();
                     $new_supported_version->ApiVersionID = 0;
                     $new_supported_version->write();
                 }
             }
         }
         $to_delete = "";
         if (count($non_versioned_components) > 0) {
             $to_delete = implode(',', $non_versioned_components);
             $to_delete = "AND OpenStackComponentID NOT IN ({$to_delete})";
         }
         DB::query("DELETE FROM OpenStackReleaseSupportedApiVersion WHERE ReleaseID = {$this->owner->getIdentifier()} AND ApiVersionID = 0 {$to_delete}");
     }
 }
コード例 #25
0
 /**
  * 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));
     }
 }
コード例 #26
0
 static function add_to_class($class, $extensionClass, $args = null)
 {
     if ($class == 'SiteConfig') {
         Config::inst()->update($class, 'defaults', array('MobileDomain' => 'http://m.' . $_SERVER['HTTP_HOST'], 'FullSiteDomain' => 'http://' . $_SERVER['HTTP_HOST']));
     }
     parent::add_to_class($class, $extensionClass, $args);
 }
コード例 #27
0
 function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->owner->ID && $this->owner->ClassName == 'ErrorPage') {
         $this->owner->ShowInSiteMap = 0;
     }
 }
コード例 #28
0
ファイル: Publishable.php プロジェクト: KINKCreative/actors
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->owner->ID && !$this->owner->PublicationDate) {
         $this->owner->PublicationDate = date("Y-m-d H:i:s");
     }
 }
 /**
  * Generates the Android manifest.json file.
  *
  * @todo Information about permissions
  *
  * @return void
  */
 public function onAfterWrite()
 {
     // parent
     parent::onAfterWrite();
     // @todo Add success & error states + messages
     $this->generateAndroidManifest();
 }
コード例 #30
0
 static function add_to_class($class, $extensionClass, $args = null)
 {
     if ($class == 'Page' || $class == "SiteConfig") {
         Config::inst()->update($class, 'db', MaxSkitterDefaults::get_skitterDbFields());
     }
     parent::add_to_class($class, $extensionClass, $args);
 }