Example #1
0
 /**
  * Constructor
  *
  * @param array $options optional load object properties
  */
 public function __construct($options = array())
 {
     if (!empty($options['connection'])) {
         $this->connection = $options['connection'];
     }
     $this->Version = ClassRegistry::init(array('class' => 'Migrations.SchemaMigration', 'ds' => $this->connection));
     $this->Version->setDataSource($this->connection);
     if (!isset($options['autoinit']) || $options['autoinit'] !== false) {
         $this->__initMigrations();
     }
 }
 /**
  * Uninstall plugin
  *
  * @param Model $model Model using this behavior
  * @param array $data Plugin data
  * @return bool True on success
  * @throws InternalErrorException
  */
 public function uninstallPlugin(Model $model, $data)
 {
     $model->loadModels(['Plugin' => 'PluginManager.Plugin', 'PluginsRole' => 'PluginManager.PluginsRole', 'PluginsRoom' => 'PluginManager.PluginsRoom']);
     //トランザクションBegin
     $model->setDataSource('master');
     $dataSource = $model->getDataSource();
     $dataSource->begin();
     if (is_string($data)) {
         $key = $data;
     } else {
         $key = $data[$model->alias]['key'];
     }
     try {
         //Pluginの削除
         if (!$model->deleteAll(array($model->alias . '.key' => $key), false)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         //PluginsRoomの削除
         if (!$model->PluginsRoom->deleteAll(array($model->PluginsRoom->alias . '.plugin_key' => $key), false)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         //PluginsRoleの削除
         if (!$model->PluginsRole->deleteAll(array($model->PluginsRole->alias . '.plugin_key' => $key), false)) {
             throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
         }
         //トランザクションCommit
         $dataSource->commit();
     } catch (Exception $ex) {
         //トランザクションRollback
         $dataSource->rollback();
         CakeLog::error($ex);
         throw $ex;
     }
     return true;
 }
Example #3
0
 /**
  * Set PicORM global configuration
  *
  * @param array $configuration
  *
  * @throws Exception
  */
 public static final function configure(array $configuration)
 {
     // override with default configuration if not present
     $configuration += static::$_defaultConfiguration;
     // test if datasource is a PDO instance
     if ($configuration['datasource'] === null || !$configuration['datasource'] instanceof \PDO) {
         throw new Exception("PDO Datasource is required!");
     }
     // set global datasource for all model
     static::$_dataSource = $configuration['datasource'];
     Model::setDataSource(static::$_dataSource);
     // store PicORM configuration
     static::$_configuration = $configuration;
 }
 /**
  * Get a new SchemaMigration instance
  *
  * @return void
  */
 public function initVersion()
 {
     $this->Version = ClassRegistry::init(array('class' => 'Migrations.SchemaMigration', 'ds' => $this->connection));
     $this->Version->setDataSource($this->connection);
 }
Example #5
0
 /**
  * Intercepts find to use the caching datasource instead
  *
  * If `$queryData['cacher']` is true, it will cache based on the setup settings
  * If `$queryData['cacher']` is a duration, it will cache using the setup settings
  * and the new duration.
  *
  * @param Model $Model The calling model
  * @param array $queryData The query
  */
 public function beforeFind(Model $Model, $queryData)
 {
     if (Configure::read('Cache.disable') === true) {
         return $queryData;
     }
     $this->cacheResults = false || $this->settings[$Model->alias]['auto'];
     if (isset($queryData['cacher'])) {
         if (is_string($queryData['cacher'])) {
             Cache::config($this->settings[$Model->alias]['config'], array('duration' => $queryData['cacher']));
             $this->cacheResults = true;
         } else {
             $this->cacheResults = (bool) $queryData['cacher'];
         }
         unset($queryData['cacher']);
     }
     if ($this->cacheResults) {
         $Model->setDataSource('cacher');
     }
     return $queryData;
 }
Example #6
0
 public function setDataSource($dataSource = null)
 {
     parent::setDataSource($dataSource);
     return $this;
 }
Example #7
0
 /**
  * Intercepts find to use the caching datasource instead
  *
  * If `$queryData['cache']` is true, it will cache based on the setup settings
  * If `$queryData['cache']` is a duration, it will cache using the setup settings
  * and the new duration.
  *
  * @param Model $model The calling model
  * @param array $query The query
  * @return array The modified query
  * @see ModelBehavior::beforeFind()
  */
 public function beforeFind(Model $model, $query)
 {
     // Get setting auto cache
     $this->_cachedResults = $this->settings[$model->alias]['auto'];
     if (isset($query['cache'])) {
         if ($query['cache'] === false) {
             $this->_cachedResults = false;
         } else {
             $this->_cachedResults = true;
             // Get cache Config Name
             if (isset($query['cache']['config']) && !empty($query['cache']['config'])) {
                 // Modified CachedSource config by query
                 $ds = ConnectionManager::getDataSource('cached');
                 $dsConfig = array('config' => $query['cache']['config']);
                 if (isset($query['cache']['gzip'])) {
                     $dsConfig['gzip'] = $query['cache']['gzip'];
                     unset($query['cache']['gzip']);
                 }
                 $ds->setConfig($dsConfig);
             } else {
                 $query['cache']['config'] = $this->settings[$model->alias]['config'];
             }
             // Modified Cache Config by query
             $cacheConfig = array();
             if (isset($query['cache']['duration'])) {
                 $cacheConfig['duration'] = $query['cache']['duration'];
                 unset($query['cache']['duration']);
             }
             Cache::config($query['cache']['config'], $cacheConfig);
             unset($query['cache']['config']);
         }
     }
     if ($this->_cachedResults) {
         $model->setDataSource('cached');
     }
     return $query;
 }
Example #8
0
 /**
  * Resets the model's datasource to the original
  *
  * @param Model $Model The model
  * @return boolean
  */
 protected function _resetSource($Model)
 {
     if (isset($Model->_useDbConfig)) {
         $this->source = ConnectionManager::getDataSource($Model->_useDbConfig);
     }
     return $Model->setDataSource(ConnectionManager::getSourceName($this->source));
 }
Example #9
0
 /**
  * Reads from cache if it exists. If not, it falls back to the original
  * datasource to retrieve the data and cache it for later
  *
  * @param Model $model
  * @param array $query
  * @param int $recursive
  * @return array Results
  * @see DataSource::read()
  */
 public function read(Model $model, $query = array(), $recursive = null)
 {
     // Resets the model's datasource to the original
     $model->setDataSource(ConnectionManager::getSourceName($this->source));
     $key = $this->_key($model, $query);
     $results = Cache::read($key, $this->config['config']);
     if ($results === false) {
         $results = $this->source->read($model, $query, $recursive);
         // compress before storing
         if ($this->_useGzip()) {
             Cache::write($key, gzcompress(serialize($results)), $this->config['config']);
         } else {
             Cache::write($key, $results, $this->config['config']);
         }
         $this->_map($model, $key);
     } else {
         // uncompress data from cache
         if ($this->_useGzip()) {
             $results = unserialize(gzuncompress($results));
         }
     }
     Cache::set(null, $this->config['config']);
     return $results;
 }