public function run(ImportedEventOccurrenceModel $importedEventOccurrenceModel) { $eventRepo = new EventRepository(); $eventRecurSetRepo = new EventRecurSetRepository(); if ($importedEventOccurrenceModel->hasReoccurence()) { // Have to load it looking for the right time to! $event = $this->loadEventForImportedReoccurredEvent($importedEventOccurrenceModel); } else { // just load it. $event = $this->loadEventForImportedEvent($importedEventOccurrenceModel); } if ($event) { $this->eventsSeenIDs[] = $event->getId(); // Set Existing Event From Import Event URL if ($importedEventOccurrenceModel->getIsDeleted()) { if (!$event->getIsDeleted()) { $eventRepo->delete($event); return true; } } else { if ($event->setFromImportedEventModel($importedEventOccurrenceModel) || $event->getIsDeleted()) { $event->setIsDeleted(false); $eventRepo->edit($event); return true; } } } else { if (!$this->importURL->getIsManualEventsCreation()) { // New Event From Import Event URL $event = $this->newEventFromImportedEventModel($importedEventOccurrenceModel); if ($this->eventRecurSet) { $event->setEventRecurSetId($this->eventRecurSet->getId()); } $eventRepo->create($event, $this->site, null, $this->group, null, $importedEventOccurrenceModel); $this->eventsSeenIDs[] = $event->getId(); if (!$this->eventRecurSet && $this->makeEventRecurSetIfNone) { $this->eventRecurSet = $eventRecurSetRepo->getForEvent($event); } return true; } else { return false; } } return false; }
public function create(ImportURLModel $importURL, SiteModel $site, UserAccountModel $creator) { global $DB; try { $DB->beginTransaction(); $stat = $DB->prepare("SELECT max(slug) AS c FROM import_url_information WHERE site_id=:site_id"); $stat->execute(array('site_id' => $site->getId())); $data = $stat->fetch(); $importURL->setSlug($data['c'] + 1); $stat = $DB->prepare("INSERT INTO import_url_information (site_id, slug, title,url,url_canonical,created_at,group_id,is_enabled,country_id,area_id, approved_at, is_manual_events_creation) " . "VALUES (:site_id, :slug, :title,:url,:url_canonical, :created_at, :group_id,:is_enabled,:country_id,:area_id,:approved_at,:is_manual_events_creation) RETURNING id"); $stat->execute(array('site_id' => $site->getId(), 'slug' => $importURL->getSlug(), 'title' => substr($importURL->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED), 'url' => substr($importURL->getUrl(), 0, VARCHAR_COLUMN_LENGTH_USED), 'url_canonical' => substr($importURL->getUrlCanonical(), 0, VARCHAR_COLUMN_LENGTH_USED), 'group_id' => $importURL->getGroupId(), 'country_id' => $importURL->getCountryId(), 'area_id' => $importURL->getAreaId(), 'created_at' => \TimeSource::getFormattedForDataBase(), 'approved_at' => \TimeSource::getFormattedForDataBase(), 'is_enabled' => $importURL->getIsEnabled() ? 1 : 0, 'is_manual_events_creation' => $importURL->getIsManualEventsCreation() ? 1 : 0)); $data = $stat->fetch(); $importURL->setId($data['id']); $stat = $DB->prepare("INSERT INTO import_url_history (import_url_id, title, user_account_id , created_at,group_id,is_enabled,country_id,area_id, approved_at, is_new, is_manual_events_creation) VALUES " . "(:curated_list_id, :title, :user_account_id , :created_at, :group_id,:is_enabled,:country_id,:area_id, :approved_at, '1', :is_manual_events_creation )"); $stat->execute(array('curated_list_id' => $importURL->getId(), 'title' => substr($importURL->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED), 'group_id' => $importURL->getGroupId(), 'country_id' => $importURL->getCountryId(), 'area_id' => $importURL->getAreaId(), 'user_account_id' => $creator->getId(), 'created_at' => \TimeSource::getFormattedForDataBase(), 'approved_at' => \TimeSource::getFormattedForDataBase(), 'is_enabled' => $importURL->getIsEnabled() ? 1 : 0, 'is_manual_events_creation' => $importURL->getIsManualEventsCreation() ? 1 : 0)); $DB->commit(); } catch (Exception $e) { $DB->rollBack(); } }
public function update(ImportURLModel $importURL, $fields, ImportURLEditMetaDataModel $importURLEditMetaDataModel) { $alreadyInTransaction = $this->db->inTransaction(); // Make Information Data $fieldsSQL1 = array(); $fieldsParams1 = array('id' => $importURL->getId()); foreach ($fields as $field) { $fieldsSQL1[] = " " . $field . "=:" . $field . " "; if ($field == 'title') { $fieldsParams1['title'] = substr($importURL->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED); } else { if ($field == 'area_id') { $fieldsParams1['area_id'] = $importURL->getAreaId(); } else { if ($field == 'is_enabled') { $fieldsParams1['is_enabled'] = $importURL->getIsEnabled() ? 1 : 0; } else { if ($field == 'is_manual_events_creation') { $fieldsParams1['is_manual_events_creation'] = $importURL->getIsManualEventsCreation() ? 1 : 0; } else { if ($field == 'country_id') { $fieldsParams1['country_id'] = $importURL->getCountryId(); } else { if ($field == 'expired_at') { $fieldsParams1['expired_at'] = $importURL->getExpiredAt() ? $importURL->getExpiredAt()->format("Y-m-d H:i:s") : null; } else { if ($field == 'group_id') { $fieldsParams1['group_id'] = $importURL->getGroupId(); } } } } } } } } // Make History Data $fieldsSQL2 = array('import_url_id', 'user_account_id', 'created_at', 'approved_at'); $fieldsSQLParams2 = array(':import_url_id', ':user_account_id', ':created_at', ':approved_at'); $fieldsParams2 = array('import_url_id' => $importURL->getId(), 'user_account_id' => $importURLEditMetaDataModel->getUserAccount() ? $importURLEditMetaDataModel->getUserAccount()->getId() : null, 'created_at' => $this->timesource->getFormattedForDataBase(), 'approved_at' => $this->timesource->getFormattedForDataBase()); if ($importURLEditMetaDataModel->getEditComment()) { $fieldsSQL2[] = ' edit_comment '; $fieldsSQLParams2[] = ' :edit_comment '; $fieldsParams2['edit_comment'] = $importURLEditMetaDataModel->getEditComment(); } foreach ($this->possibleFields as $field) { if (in_array($field, $fields) || $field == 'title') { $fieldsSQL2[] = " " . $field . " "; $fieldsSQLParams2[] = " :" . $field . " "; if ($field == 'title') { $fieldsParams2['title'] = substr($importURL->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED); } else { if ($field == 'area_id') { $fieldsParams2['area_id'] = $importURL->getAreaId(); } else { if ($field == 'country_id') { $fieldsParams2['country_id'] = $importURL->getCountryId(); } else { if ($field == 'group_id') { $fieldsParams2['group_id'] = $importURL->getGroupId(); } else { if ($field == 'expired_at') { $fieldsParams2['expired_at'] = $importURL->getExpiredAt() ? $importURL->getExpiredAt()->format("Y-m-d H:i:s") : null; } else { if ($field == 'is_enabled') { $fieldsParams2['is_enabled'] = $importURL->getIsEnabled() ? 1 : 0; } else { if ($field == 'is_manual_events_creation') { $fieldsParams2['is_manual_events_creation'] = $importURL->getIsManualEventsCreation() ? 1 : 0; } } } } } } } $fieldsSQL2[] = " " . $field . "_changed "; $fieldsSQLParams2[] = " 0 "; } else { $fieldsSQL2[] = " " . $field . "_changed "; $fieldsSQLParams2[] = " -2 "; } } try { if (!$alreadyInTransaction) { $this->db->beginTransaction(); } // Information SQL $stat = $this->db->prepare("UPDATE import_url_information SET " . implode(",", $fieldsSQL1) . " WHERE id=:id"); $stat->execute($fieldsParams1); // History SQL $stat = $this->db->prepare("INSERT INTO import_url_history (" . implode(",", $fieldsSQL2) . ") VALUES (" . implode(",", $fieldsSQLParams2) . ")"); $stat->execute($fieldsParams2); if (!$alreadyInTransaction) { $this->db->commit(); } } catch (Exception $e) { if (!$alreadyInTransaction) { $this->db->rollBack(); } throw $e; } }