function commit() { $this->findDefaultData(); $EntryManager = new EntryManager($this->_engine); return $this->get('id') ? $EntryManager->edit($this) : $EntryManager->add($this); }
/** * Commits this Entry's data to the database, by first finding the default * data for this `Entry` and then utilising the `EntryManager`'s * add or edit function. The `EntryManager::edit` function is used if * the current `Entry` object has an ID, otherwise `EntryManager::add` * is used. * * @see toolkit.Entry#findDefaultData() * @return boolean * true if the commit was successful, false otherwise. */ public function commit() { $this->findDefaultData(); return $this->get('id') ? EntryManager::edit($this) : EntryManager::add($this); }
public function commit() { $options = $this->options(); $existing = array(); $section = SectionManager::fetch($options['section']); if ((int) $options['unique-field'] > 0) { $field = FieldManager::fetch($options['unique-field']); if (!empty($field)) { foreach ($this->_entries as $index => $current) { $entry = $current['entry']; $data = $entry->getData($options['unique-field']); $where = $joins = $group = null; $field->buildDSRetrievalSQL($data, $joins, $where); $group = $field->requiresSQLGrouping(); $entries = EntryManager::fetch(null, $options['section'], 1, null, $where, $joins, $group, false, null, false); if (is_array($entries) && !empty($entries)) { $existing[$index] = $entries[0]['id']; } else { $existing[$index] = null; } } } } foreach ($this->_entries as $index => $current) { $entry = $current['entry']; $values = $current['values']; $date = DateTimeObj::get('Y-m-d H:i:s'); $dateGMT = DateTimeObj::getGMT('Y-m-d H:i:s'); $exists = !empty($existing[$index]); $skip = $options['can-update'] !== 'yes'; // Skip entry if ($exists && $skip) { $entry->set('importer_status', 'skipped'); ### # Delegate: XMLImporterEntryPostSkip # Description: Skipping an entry. Entry object is provided. Symphony::ExtensionManager()->notifyMembers('XMLImporterEntryPostSkip', '/xmlimporter/importers/run/', array('section' => $section, 'entry' => $entry, 'fields' => $values)); } elseif ($exists) { $entry->set('id', $existing[$index]); $entry->set('modification_date', $date); $entry->set('modification_date_gmt', $dateGMT); ### # Delegate: XMLImporterEntryPreEdit # Description: Just prior to editing of an Entry. Symphony::ExtensionManager()->notifyMembers('XMLImporterEntryPreEdit', '/xmlimporter/importers/run/', array('section' => $section, 'fields' => &$values, 'entry' => &$entry)); EntryManager::edit($entry); $entry->set('importer_status', 'updated'); ### # Delegate: XMLImporterEntryPostEdit # Description: Editing an entry. Entry object is provided. Symphony::ExtensionManager()->notifyMembers('XMLImporterEntryPostEdit', '/xmlimporter/importers/run/', array('section' => $section, 'entry' => $entry, 'fields' => $values)); } else { $entry->set('creation_date', $date); $entry->set('creation_date_gmt', $dateGMT); $entry->set('modification_date', $date); $entry->set('modification_date_gmt', $dateGMT); ### # Delegate: XMLImporterEntryPreCreate # Description: Just prior to creation of an Entry. Entry object provided Symphony::ExtensionManager()->notifyMembers('XMLImporterEntryPreCreate', '/xmlimporter/importers/run/', array('section' => $section, 'fields' => &$values, 'entry' => &$entry)); EntryManager::add($entry); $entry->set('importer_status', 'created'); ### # Delegate: XMLImporterEntryPostCreate # Description: Creation of an Entry. New Entry object is provided. Symphony::ExtensionManager()->notifyMembers('XMLImporterEntryPostCreate', '/xmlimporter/importers/run/', array('section' => $section, 'entry' => $entry, 'fields' => $values)); } } }