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(); } }
/** * Gets event list * * @param \DateTime $start Start date of the period * @param \DateTime $end End date of the period * @param string $ccId optional Cost center id * @param string $projectId optional Project id * @return ArrayCollection Returns collection of the TimelineEventEntity objects */ public function get($start, $end, $ccId = null, $projectId = null) { $eventEntity = new TimelineEventEntity(); $joinData = $this->buildJoin($ccId, $projectId); $fields = ''; foreach ($eventEntity->getIterator()->fields() as $field) { $fields .= ',`' . $field->column->name . '`'; } $result = $this->db->Execute("\n SELECT " . ltrim($fields, ',') . "\n FROM (\n SELECT " . $eventEntity->fields('e') . "\n FROM " . $eventEntity->table('e') . (isset($joinData['join']) ? $joinData['join'] : '') . "\n WHERE e.dtime BETWEEN " . $eventEntity->qstr('dtime', $start) . " AND " . $eventEntity->qstr('dtime', $end) . "\n " . (isset($joinData['join']) ? "\n UNION\n SELECT " . $eventEntity->fields('e2') . "\n FROM " . $eventEntity->table('e2') . "\n WHERE e2.event_type = " . $eventEntity::EVENT_TYPE_CHANGE_CLOUD_PRICING . "\n AND e2.dtime BETWEEN " . $eventEntity->qstr('dtime', $start) . " AND " . $eventEntity->qstr('dtime', $end) : "") . "\n ) p\n ORDER BY p.dtime DESC\n "); $events = new ArrayCollection(); while ($record = $result->FetchRow()) { $item = new TimelineEventEntity(); $item->load($record); $events->append($item); } return $events; }