/** * Retrieve the User record associated with the authenticated user. * * @return User|null */ public function init() { $this->getBootstrap()->bootstrap('Auth'); $auth = $this->getBootstrap()->getResource('Auth'); $this->getBootstrap()->bootstrap('Db'); $db = $this->getBootstrap()->getResource('Db'); $front = Zend_Controller_Front::getInstance(); $request = new Zend_Controller_Request_Http(); // REST API requests require a slightly different authentication // strategy. They use non-persistant, key-based authentication if ($front->getParam('api')) { // Authenticate against the API key in a non-persistent way. $auth->setStorage(new Zend_Auth_Storage_NonPersistent()); $authAdapter = new Omeka_Auth_Adapter_KeyTable($request->getParam('key')); $auth->authenticate($authAdapter); } if (!$auth->hasIdentity()) { // There is no user if there is no identity. return null; } try { // Get the user ID for REST API or standard requests. if ($front->getParam('api')) { // Update the key row. $key = $auth->getIdentity(); $key->ip = inet_pton($request->getClientIp()); $key->accessed = date('Y-m-d H:i:s'); $key->save(); $userId = $key->user_id; } else { $userId = $auth->getIdentity(); } $user = $db->getTable('User')->findActiveById($userId); } catch (Zend_Db_Statement_Exception $e) { // Exceptions may be thrown because the database is out of sync with // the code. Suppress errors and skip authentication, but only // until the database is properly upgraded. if (Omeka_Db_Migration_Manager::getDefault()->dbNeedsUpgrade()) { $user = null; } else { throw $e; } } if (!$user) { // If we can't retrieve the User from the database, it likely means // that this user has been deleted. In this case, do not allow the // user to stay logged in. $auth->clearIdentity(); } return $user; }
/** * If necessary, convert from the old sequentially-numbered migration scheme * to the new timestamped migrations. * * @param array Omeka options. * @return void. */ private function _convertMigrationSchema(array $options) { if (!isset($options[Omeka_Db_Migration_Manager::ORIG_MIGRATION_OPTION_NAME])) { return; } // 47 is the migration of the completely-updated 1.2.x database. // Due to the changed migrations starting with 1.3, we must disallow // upgrades from pre-1.2.x versions to post-1.2 versions. if ($options[Omeka_Db_Migration_Manager::ORIG_MIGRATION_OPTION_NAME] != '47') { throw new Omeka_Db_Migration_Exception(); } $migrationManager = Omeka_Db_Migration_Manager::getDefault($this->getBootstrap()->db); $migrationManager->setupTimestampMigrations(); }
/** * Run the migration script, obtain any success/error output and display it in a pretty way * * @return void **/ public function migrateAction() { $manager = Omeka_Db_Migration_Manager::getDefault(); if (!$manager->canUpgrade()) { throw new Omeka_Db_Migration_Exception('Omeka is unable to upgrade.'); } $this->view->success = false; try { $manager->migrate(); $manager->finalizeDbUpgrade(); $this->view->success = true; } catch (Omeka_Db_Migration_Exception $e) { $this->view->error = $e->getMessage(); $this->view->exception = $e; } catch (Zend_Db_Exception $e) { $this->view->error = __("SQL error in migration: ") . $e->getMessage(); $this->view->exception = $e; } }
/** * Run the migration script, obtain any success/error output and display it in a pretty way * * @return void **/ public function migrateAction() { $manager = Omeka_Db_Migration_Manager::getDefault(); if (!$manager->canUpgrade()) { throw new Omeka_Db_Migration_Exception('Omeka is unable to upgrade.'); } $debugMode = (bool) $this->getInvokeArg('bootstrap')->config->debug->exceptions; $this->view->debugMode = $debugMode; $this->view->success = false; try { $manager->migrate(); $manager->finalizeDbUpgrade(); $this->view->success = true; } catch (Omeka_Db_Migration_Exception $e) { $this->view->error = $e->getMessage(); $this->view->trace = $e->getTraceAsString(); } catch (Zend_Db_Exception $e) { $this->view->error = __("SQL error in migration: ") . $e->getMessage(); $this->view->trace = $e->getTraceAsString(); } }
private function _dbCanUpgrade() { $migrationManager = Omeka_Db_Migration_Manager::getDefault(); return $migrationManager->canUpgrade(); }
public function install(Omeka_Db $db) { $manager = Omeka_Db_Migration_Manager::getDefault($db); $manager->setupTimestampMigrations(); $manager->markAllAsMigrated(); }