Source of file DeploymentNote.php
Size: 16,762 Bytes - Last Modified: 2021-12-23T10:57:30+00:00
/var/www/docs.ssmods.com/process/src/src/Model/DeploymentNote.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 | <?php namespace WebbuildersGroup\DeploymentNotes\Model; use SilverStripe\Control\Controller; use SilverStripe\Control\Director; use SilverStripe\Core\Config\Config; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\DateField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\NumericField; use SilverStripe\Forms\OptionsetField; use SilverStripe\Forms\RequiredFields; use SilverStripe\Forms\TextField; use SilverStripe\ORM\CMSPreviewable; use SilverStripe\ORM\DataObject; use SilverStripe\Security\Permission; use WebbuildersGroup\DeploymentNotes\Control\DeploymentSchedule; use WebbuildersGroup\DeploymentNotes\Control\Admin\DeploymentScheduleAdmin; use WebbuildersGroup\DeploymentNotes\Forms\MarkdownField; use WebbuildersGroup\DeploymentNotes\Model\FieldType\Markdown; use DateTime; /** * Class DeploymentNote * * @property string $DeploymentStart * @property string $DeploymentWeekEnd * @property string $Date * @property string $DeploymentNotes * @property boolean $Visible * @property boolean $OutOfCycle * @property boolean $CycleResetter * @property boolean $DowntimeRequired * @property int $DowntimeEstimate * @property string $DowntimeReason * @property string $Status */ class DeploymentNote extends DataObject implements CMSPreviewable { private static $db=array( 'DeploymentStart'=>'Date', 'DeploymentWeekEnd'=>'Date', 'Date'=>'Date', 'DeploymentNotes'=>Markdown::class, 'Visible'=>'Boolean', 'OutOfCycle'=>'Boolean', 'CycleResetter'=>'Boolean', 'DowntimeRequired'=>'Boolean', 'DowntimeEstimate'=>'Int', 'DowntimeReason'=>'Varchar(400)', 'Status'=>"Enum(array('planning', 'dev', 'staged', 'deployed'), 'planning')" ); private static $defaults=array( 'Visible'=>false, 'OutOfCycle'=>false, 'DowntimeRequired'=>false, 'Status'=>'planning' ); private static $default_sort='DeploymentWeekEnd DESC'; private static $summary_fields=array( 'Visible.Nice'=>'_Visible to Users', 'DeploymentStart'=>'_Cycle Start Date', 'DeploymentWeekEnd'=>'_Deployment Week', 'Date'=>'_Actual Deployment Date', 'StatusNice'=>'_Deployment Status', 'OutOfCycle.Nice'=>'_Out of Cycle' ); private static $table_name='DeploymentNote'; /** * Checks to see if the member can view this deployment note or not * @param int|Member $member Member ID or instance to check * @return bool Returns boolean true if the member can view this deployment note */ public function canView($member=null) { return ( ($this->Visible && (DeploymentScheduleAdmin::config()->view_permission_code===false || Permission::check(DeploymentScheduleAdmin::config()->view_permission_code, 'any', $member))) || Permission::check('CMS_ACCESS_'.DeploymentScheduleAdmin::class, 'any', $member)==true ); } /** * Checks to see if the member can create a deployment note or not * @param int|Member $member Member ID or instance to check * @return bool Returns boolean true if the member can create a deployment note */ public function canCreate($member=null, $context=array()) { if(DeploymentScheduleAdmin::config()->strict_permission_check) { //Get the old value for Permission.admin_implies_all $oldValue=Config::inst()->get(Permission::class, 'admin_implies_all'); //Disable the Permission.admin_implies_all Config::inst()->update(Permission::class, 'admin_implies_all', false); } $result=(Permission::check('CMS_ACCESS_'.DeploymentScheduleAdmin::class, 'any', $member)==true); if(DeploymentScheduleAdmin::config()->strict_permission_check) { //Restore the value for Permission.admin_implies_all Config::inst()->update(Permission::class, 'admin_implies_all', $oldValue); } return $result; } /** * Checks to see if the member can edit this deployment note or not * @param int|Member $member Member ID or instance to check * @return bool Returns boolean true if the member can edit this deployment note */ public function canEdit($member=null) { if(DeploymentScheduleAdmin::config()->strict_permission_check) { //Get the old value for Permission.admin_implies_all $oldValue=Config::inst()->get(Permission::class, 'admin_implies_all'); //Disable the Permission.admin_implies_all Config::inst()->update(Permission::class, 'admin_implies_all', false); } $result=(Permission::check('CMS_ACCESS_'.DeploymentScheduleAdmin::class, 'any', $member)==true); if(DeploymentScheduleAdmin::config()->strict_permission_check) { //Restore the value for Permission.admin_implies_all Config::inst()->update(Permission::class, 'admin_implies_all', $oldValue); } return $result; } /** * Checks to see if the member can delete this deployment note or not * @param int|Member $member Member ID or instance to check * @return bool Returns boolean true if the member can delete this deployment note */ public function canDelete($member=null) { if(DeploymentScheduleAdmin::config()->strict_permission_check) { //Get the old value for Permission.admin_implies_all $oldValue=Config::inst()->get(Permission::class, 'admin_implies_all'); //Disable the Permission.admin_implies_all Config::inst()->update(Permission::class, 'admin_implies_all', false); } $result=(Permission::check('CMS_ACCESS_'.DeploymentScheduleAdmin::class, 'any', $member)==true); if(DeploymentScheduleAdmin::config()->strict_permission_check) { //Restore the value for Permission.admin_implies_all Config::inst()->update(Permission::class, 'admin_implies_all', $oldValue); } return $result; } /** * Gets fields used in the cms * @return FieldList Fields to be used */ public function getCMSFields() { $startDate=null; $endDate=null; if(!$this->exists()) { $prevDeploy=DeploymentNote::get()->first(); if(!empty($prevDeploy) && $prevDeploy!==false && $prevDeploy->exists()) { $startDate=date('Y-m-d', strtotime($prevDeploy->DeploymentWeekEnd.' -4 days')); $endDate=date('Y-m-d', strtotime($startDate.' +'.DeploymentSchedule::config()->deployment_cycle_length.' weeks friday')); }else { $startDate=date('Y-m-d', strtotime('monday this week')); $endDate=date('Y-m-d', strtotime($startDate.' +'.DeploymentSchedule::config()->deployment_cycle_length.' weeks friday')); } } $fields=new FieldList( new CheckboxField('Visible', _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.db_Visible_Nice', '_Visible to Users?')), DateField::create('DeploymentStart', _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.db_DeploymentStart', '_Cycle Start Date'), $startDate), DateField::create('DeploymentWeekEnd', _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.WEEK_END', '_Deployment Week End Date'), $endDate), DateField::create('Date', _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.db_Date', '_Actual Deployment Date')), new MarkdownField('DeploymentNotes', _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.DEPLOYMENT_NOTES', '_Deployment Notes'), '### '._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.PLANNED_TITLE', '_Planned Changes').":\n\n". '_'._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.PLANNED_DESC', '_Planned Changes are scheduled to be included in this deployment however they maybe pushed to a future deployment.')."_\n\n". '* '._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.TBA', '_TBA')."\n\n\n". '### '._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.HIGH_LEVEL', '_High Level').":\n\n". '* '._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.TBA', '_TBA')."\n\n\n". '### '._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.BUGS_BEHIND_MINOR', '_Bug Fixes/Behind the Scenes/Minor').":\n\n". '* '._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.TBA', '_TBA')."\n\n\n". '### '._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.KNOWN_ISSUES', '_Known Issues').":\n\n". '* '._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.NONE', '_None')."\n\n\n". '### '._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.KEY_TESTING', '_Key Testing Areas').":\n\n". '* '._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.TBA', '_TBA')."\n\n\n". '### '._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.POST_STAGING', '_Post Staging Changes').":\n\n". '* '._t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.TBA', '_TBA')."\n"), new OptionsetField('Status', 'Deployment Status', array( 'planning'=>_t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.PLANNING', '_Planning'), 'dev'=>_t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.IN_DEV', '_In Development'), 'staged'=>_t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.STAGING_TESTING', '_On Staging/In Testing'), 'deployed'=>_t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.DEPLOYED', '_Deployed to Production') ), 'planning'), new CheckboxField('DowntimeRequired', _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.DOWNTIME_REQUIRED', '_Is Downtime Required?')), NumericField::create('DowntimeEstimate', _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.DOWNTIME_EST_LENGTH', '_Estimated downtime length in minutes'))->displayIf('DowntimeRequired')->isChecked()->end(), TextField::create('DowntimeReason', _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.DOWNTIME_REASON', '_Reason for Downtime'), null, 400)->displayIf('DowntimeRequired')->isChecked()->end(), new CheckboxField('OutOfCycle', _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.OUT_OF_CYCLE', '_Out of Cycle Deployment?')), new CheckboxField('CycleResetter', _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.RESETS_CYCLE', '_Resets the Deployment Cycle?')) ); return $fields; } /** * Gets the date formatted from settings * @return string */ public function getTitle() { return _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.WEEK_OF_DEPLOYMENT', '_Week of {week_end_date} Deployment', array('week_end_date'=>$this->dbObject('DeploymentWeekEnd')->FormatFromSettings())); } /** * Gets validator used in the cms * @return Validator Validator to be used */ public function getCMSValidator() { return new RequiredFields( 'DeploymentStart', 'DeploymentWeekEnd', 'DeploymentNotes', 'Status' ); } /** * Gets the friendly descriptions for the status enum * @return string */ public function getStatusNice() { switch($this->Status) { case 'planning':return _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.PLANNING', '_Planning'); case 'dev':return _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.IN_DEV', '_In Development'); case 'staged':return _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.STAGING_TESTING', '_On Staging/In Testing'); case 'deployed':return _t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.DEPLOYED', '_Deployed to Production'); } } /** * Gets the Relative Link to this note * @param string $action Action to append to the url * @return string */ public function Link($action=null) { return Controller::join_links('deployment-schedule', 'note', $this->ID, $action, '/'); } /** * Gets the Absolute Link to this note * @param string $action Action to append to the url * @return string */ public function AbsoluteLink($action=null) { return Director::absoluteURL($this->Link($action)); } /** * Detects if this deployment has an abnormal cycle * @return bool */ public function getIsOddCycle() { return (round(DateTime::createFromFormat('Y-m-d', $this->DeploymentStart)->diff(DateTime::createFromFormat('Y-m-d', $this->DeploymentWeekEnd))->days/7)>DeploymentSchedule::config()->deployment_cycle_length+DeploymentSchedule::config()->planning_period_length); } /** * Link to view the canonical segment * @return string Link to view the canonical segment */ public function PreviewLink($action=null) { if($this->hasMethod('alternatePreviewLink')) { return $this->alternatePreviewLink(); }else { return $this->AbsoluteLink(); } } /** * Gets the link to edit in the cms * @return string */ public function CMSEditLink() { return Director::absoluteURL('admin/deployment-schedule/DeploymentNote/EditForm/field/DeploymentNote/item/'.$this->ID.'/edit'); } /** * Get the default summary fields for this object. * @return array */ public function summaryFields() { $fields=$this->stat('summary_fields'); foreach($fields as $key=>$value) { $fields[$key]=_t('WebbuildersGroup\\DeploymentNotes\\Model\\DeploymentNote.db_'.str_replace('.', '_', $key), $value); } return $fields; } /** * To determine preview mechanism (e.g. embedded / iframe) * @return string */ public function getMimeType() { return 'text/html'; } } ?> |