/** * Delegate to the database adapter. * * Used primarily as a convenience method. For example, you can call * fetchOne() and fetchAll() directly from this object. * * @param string $m Method name. * @param array $a Method arguments. * @return mixed */ public function __call($m, $a) { if (!method_exists($this->_db, $m) && !method_exists($this->_db->getAdapter(), $m)) { throw new BadMethodCallException("Method named '{$m}' does not exist or is not callable."); } return call_user_func_array(array($this->_db, $m), $a); }
public function install(Omeka_Db $db) { $givenOptions = array_keys($this->_options); if ($missingOptions = array_diff($this->_expectedOptions, $givenOptions)) { $optStr = join(', ', $missingOptions); throw new Installer_Task_Exception("Missing the following options: {$optStr}."); } if ($unknownOptions = array_diff($givenOptions, $this->_expectedOptions)) { $optStr = join(', ', $unknownOptions); throw new Installer_Task_Exception("Unknown options given: {$optStr}."); } foreach ($this->_options as $name => $value) { $db->insert('Option', array('name' => $name, 'value' => $value)); } }
/** * @param string|null $tableName * @return Omeka_Db_Table */ public function getTable($tableName = null) { if (!$tableName) { if (!$this->_defaultTable) { throw new InvalidArgumentException("Default table must be assigned."); } return $this->_defaultTable; } else { return $this->_db->getTable($tableName); } }
public function install(Omeka_Db $db) { if (empty($this->_tables)) { throw new Installer_Task_Exception("No SQL files were given to create the schema."); } foreach ($this->_tables as $tableName => $sqlFilePath) { try { $db->loadSqlFile($sqlFilePath); } catch (Zend_Db_Exception $e) { throw new Installer_Task_Exception("Schema task failed" . " on table '" . $db->prefix . $tableName . "' with " . get_class($e) . ": " . $e->getMessage()); } } }
/** * @return Omeka_Db */ public function init() { $dbFile = $this->_iniPath; if (!file_exists($dbFile)) { throw new Zend_Config_Exception('Your Omeka database configuration file is missing.'); } if (!is_readable($dbFile)) { throw new Zend_Config_Exception('Your Omeka database configuration file cannot be read by the application.'); } $dbIni = new Zend_Config_Ini($dbFile, 'database'); // Fail on improperly configured db.ini file if (!isset($dbIni->host) || $dbIni->host == 'XXXXXXX') { throw new Zend_Config_Exception('Your Omeka database configuration file has not been set up properly. Please edit the configuration and reload this page.'); } $connectionParams = $dbIni->toArray(); // dbname aliased to 'name' for backwards-compatibility. if (array_key_exists('name', $connectionParams)) { $connectionParams['dbname'] = $connectionParams['name']; } $bootstrap = $this->getBootstrap(); $bootstrap->bootstrap('Config'); $config = $this->getBootstrap()->getResource('Config'); $loggingEnabled = $config->log->sql; $profilingEnabled = $config->debug->profileDb; if ($profilingEnabled) { $connectionParams['profiler'] = true; } $dbh = Zend_Db::factory('Mysqli', $connectionParams); $db_obj = new Omeka_Db($dbh, $dbIni->prefix); // Enable SQL logging (potentially). if ($loggingEnabled) { $bootstrap->bootstrap('Logger'); $db_obj->setLogger($bootstrap->getResource('Logger')); } Zend_Db_Table_Abstract::setDefaultAdapter($dbh); return $db_obj; }
/** * For a given record, re-save the remote parent record, if one exists. * * @param Omeka_Record $record The record. * * @author David McClure <*****@*****.**> **/ public function resaveRemoteParent($record) { // Get the record type. $table = get_class($record); // Iterate over all addon fields. foreach ($this->addons as $addon) { foreach ($addon->fields as $field) { // Match remote fields that point to the record's type. if ($field->remote && $field->remote->table == $table) { $parentTable = $this->db->getTable($addon->table); $parentIdKey = $field->remote->key; // Load the parent and re-save. $parent = $parentTable->find($record->{$parentIdKey}); $parent->save(); } } } }
/** * This returns true if this addon (and none of its ancestors) are flagged. * * @param Omeka_Record $record The Omeka record to consider indexing. * @param SolrSearch_Addon_Addon $addon The addon for the record. * * @return bool $indexed A flag indicating whether to index the record. * @author Eric Rochester <*****@*****.**> **/ public function isRecordIndexed($record, $addon) { $indexed = true; if (is_null($record)) { } else { if (!is_null($addon->flag)) { $flag = $addon->flag; $indexed = $record->{$flag}; } else { if (!is_null($addon->parentAddon)) { $key = $addon->parentKey; $table = $this->db->getTable($addon->parentAddon->table); $parent = $table->find($record->{$key}); $indexed = $this->isRecordIndexed($parent, $addon->parentAddon); } } } return $indexed; }
/** * Set the record upon which this builder will act. * * @see Omeka_Record_Builder::getRecord() * @param Omeka_Record_AbstractRecord|integer|null $record * @return void */ public function setRecord($record = null) { if ($record === null) { $this->_record = new $this->_recordClass($this->_db); } else { if ($record instanceof Omeka_Record_AbstractRecord) { if (!$record instanceof $this->_recordClass) { throw new Omeka_Record_Builder_Exception("Incorrect record instance given. Must be instance of '{$this->_recordClass}'."); } $this->_record = $record; } else { if (is_int($record)) { $this->_record = $this->_db->getTable($this->_recordClass)->find($record); if (!$this->_record) { throw new Omeka_Record_Builder_Exception("Could not find record with ID = " . $record); } } else { throw new InvalidArgumentException("Argument passed to setRecord() must be Omeka_Record_AbstractRecord, integer, or null."); } } } }
/** * Return an Omeka file object. * * @param int $fileId * @return File|int */ private function _getFile($fileId) { return $this->_db->getTable('File')->find($fileId); }
private function _enableSqlLogging(Omeka_Db $db) { $bs = $this->getBootstrap(); $loggingEnabled = ($config = $bs->getResource('Config')) && $config->log->sql; if ($loggingEnabled) { $bs->bootstrap('Logger'); $db->setLogger($bs->getResource('Logger')); } }
/** * @param Omeka_Db $db Database object. */ public function __construct(Omeka_Db $db) { parent::__construct($db->getAdapter(), $db->User, 'username', 'password', 'SHA1(CONCAT(salt, ?)) AND active = 1'); }
/** * Record the migration timestamp in the schema_migrations table. * * @param string $time * @return void */ private function _recordMigration($time) { $this->_db->getAdapter()->insert($this->_getMigrationTableName(), array('version' => $time)); }