Since: 5.0
Author: Vlad Dobrovolskiy (v.dobrovolskiy@scalr.com)
Inheritance: extends Scalr\Model\AbstractEntity
Beispiel #1
0
 protected function run1($stage)
 {
     $this->db->Execute('
         ALTER TABLE `timeline_events`
             ADD `account_id` int(11) NULL AFTER `user_id`,
             ADD `env_id` int(11) NULL AFTER `account_id`,
             ADD INDEX `idx_account_id` (`account_id` ASC),
             ADD INDEX `idx_env_id` (`env_id` ASC)
     ');
     $res = $this->db->Execute('SELECT * FROM timeline_events');
     while ($item = $res->FetchRow()) {
         $event = new TimelineEventEntity();
         $event->load($item);
         try {
             $event->accountId = \Scalr_Account_User::init()->loadById($event->userId)->getAccountId();
         } catch (Exception $e) {
             continue;
         }
         $event->save();
     }
 }
Beispiel #2
0
 /**
  * Fires an event
  *
  * @return boolean Returns true if a new record has been added
  */
 public function fire()
 {
     $this->timelineEvent->uuid = $this->timelineEvent->type('uuid')->toPhp(substr(hash('sha1', $this->messageToHash, true), 0, 16));
     if (!$this->timelineEvent->findPk($this->timelineEvent->uuid)) {
         $this->timelineEvent->description = $this->message;
         $this->timelineEvent->save();
         //Creates timeline event records for events which affect cost centers
         foreach (array_filter($this->ccs, [$this, 'callbackFilter']) as $ccId) {
             $entity = new TimelineEventCostCentreEntity($this->timelineEvent->uuid, $ccId);
             $entity->save();
         }
         //Creates timeline event records for events which affect projects
         foreach (array_filter($this->projects, [$this, 'callbackFilter']) as $projectId) {
             $entity = new TimelineEventProjectEntity($this->timelineEvent->uuid, $projectId);
             $entity->save();
         }
         return true;
     }
     return false;
 }
Beispiel #3
0
 /**
  * Buld join sql statement part
  *
  * @param string $ccId      optional Cost center id
  * @param string $projectId optional Project id
  * @return array            Returns array of prepared data for join sql statement
  */
 private function buildJoin($ccId = null, $projectId = null)
 {
     $join = [];
     if (!empty($projectId)) {
         $eventTable = 'projects';
         $field = 'project_id';
         $value = $projectId;
     } else {
         if (!empty($ccId)) {
             $eventTable = 'ccs';
             $field = 'cc_id';
             $value = $ccId;
         }
     }
     if (!empty($eventTable)) {
         $eventEntity = new TimelineEventEntity();
         $eventTable = 'timeline_event_' . $eventTable;
         $join['join'] = " JOIN " . $eventTable . " t ON e.uuid = t.`event_id` AND t." . $field . " = " . $eventEntity->qstr('uuid', $value);
     }
     return $join;
 }