/** * caching the meta info * * @return unknown */ function availableTables($force_lookup = false) { $available_tables = array(); !AK_TEST_MODE && $available_tables = Ak::getStaticVar('available_tables'); if(!$force_lookup && empty($available_tables)){ if (($available_tables = AkDbSchemaCache::get('avaliable_tables')) === false) { if(empty($available_tables)){ $available_tables = $this->connection->MetaTables(); } AkDbSchemaCache::set('avaliable_tables', $available_tables); !AK_TEST_MODE && Ak::setStaticVar('available_tables', $available_tables); } } $available_tables = $force_lookup ? $this->connection->MetaTables() : $available_tables; $force_lookup && !AK_TEST_MODE && Ak::setStaticVar('available_tables', $available_tables); return $available_tables; }
public function _config($key = null, $value = null, $environment = AK_ENVIRONMENT, $unset = false) { if (AkDbSchemaCache::shouldRefresh()) { return false; } static $config; if (!isset($config[$environment])) { $file_name = AkDbSchemaCache::getCacheFileName($environment); $config[$environment] = file_exists($file_name) ? unserialize(Ak::file_get_contents($file_name)) : array(); if (AK_LOG_EVENTS) { $Logger =& Ak::getLogger(); $Logger->message('Loading cached database settings'); } } if (!is_null($key)) { if (!is_null($value)) { $config[$environment][$key] = $value; } elseif ($unset) { unset($config[$environment][$key]); } return isset($config[$environment][$key]) ? $config[$environment][$key] : false; } return $config[$environment]; }
function dropSequence($table_name) { require_once(AK_LIB_DIR.DS.'AkActiveRecord'.DS.'AkDbSchemaCache.php'); AkDbSchemaCache::clear($table_name); $result = $this->tableExists('seq_'.$table_name) ? $this->db->connection->DropSequence('seq_'.$table_name) : true; if($result){ unset($this->available_tables[array_search('seq_'.$table_name, $this->available_tables)]); } return $result; }
function resetFrameworkDatabaseTables() { require_once(AK_APP_DIR.DS.'installers'.DS.'framework_installer.php'); $installer = new FrameworkInstaller(); $installer->uninstall(); $installer->install(); AkDbSchemaCache::clearAll(); }
/** * @access private */ function _clearPersitedColumnSettings() { AkDbSchemaCache::clear($this->getModelName()); }
private function _createMigrationsTableIfNeeded() { if (!$this->tableExists('akelos_migrations')) { AkDbSchemaCache::clearAll(); $this->data_dictionary = $this->db->getDictionary(); $this->available_tables = $this->getAvailableTables(); $this->createTable('akelos_migrations', 'id, name, version int'); $this->addIndex('akelos_migrations', 'UNIQUE name', 'unq_name'); } }
function _set($type, $config, $environment = AK_ENVIRONMENT, $force = false, $var_export = false) { if ($var_export === false) { $cache = serialize($config); } else { $cacheStr = var_export($config,true); $cache = <<<EOF <?php \$cache = $cacheStr; return \$cache; ?> EOF; } $cacheFileName = AkDbSchemaCache::_generateCacheFileName($type,$environment); $cacheDir = dirname($cacheFileName); if (!file_exists($cacheDir)) { $oldumask = umask(); umask(0); $res = @mkdir($cacheDir,0777,true); if (!$res) { trigger_error(Ak::t('Could not create config cache dir %dir',array('%dir'=>$cacheDir)),E_USER_ERROR); } umask($oldumask); } $fh = fopen($cacheFileName,'w+'); if ($fh) { fputs($fh,$cache); fclose($fh); @chmod($cacheFileName,0777); } else { trigger_error(Ak::t('Could not create dbschema cache file %file',array('%file'=>$cacheFileName)),E_USER_ERROR); } AkDbSchemaCache::_get($type, $environment, false, $config); }
/** * Gets information from the database engine about a single table */ private function _databaseTableInternals($table) { if (!($cache = AkDbSchemaCache::get('table_internals_for_' . $table))) { $cache = $this->_db->getColumnDetails($table); AkDbSchemaCache::set('table_internals_for_' . $table, $cache); } return $cache; }
function removeIndex($table_name, $columns_or_index_name) { require_once(AK_LIB_DIR.DS.'AkActiveRecord'.DS.'AkDbSchemaCache.php'); AkDbSchemaCache::clear($table_name); if(!$this->tableExists($table_name)){ return false; } $available_indexes = $this->db->getIndexes($table_name); $index_name = isset($available_indexes[$columns_or_index_name]) ? $columns_or_index_name : 'idx_'.$table_name.'_'.$columns_or_index_name; if(!isset($available_indexes[$index_name])){ trigger_error(Ak::t('Index %index_name does not exist.', array('%index_name'=>$index_name)), E_USER_NOTICE); return false; } return $this->data_dictionary->ExecuteSQLArray($this->data_dictionary->DropIndexSQL($index_name, $table_name)); }
public function Test_of_loadColumnsSettings() { AkDbSchemaCache::shouldRefresh(false); $AkTestField = new AkTestField(); $AkTestField->loadColumnsSettings(); // Testing database settings cache on session (this might be changed in a future $this->assertEqual($AkTestField->_columnsSettings, AkDbSchemaCache::get('AkTestField_column_settings')); AkDbSchemaCache::shouldRefresh(true); }
function Test_of_loadColumnsSettings() { $AkTestField = new AkTestField(); $AkTestField->loadColumnsSettings(); // Testing database settings cache on session (this might be changed in a future AkDbSchemaCache::doRefresh(false); $this->assertEqual($AkTestField->_columnsSettings, AkDbSchemaCache::getModelColumnSettings('AkTestField')); AkDbSchemaCache::doRefresh(true); }