Example #1
0
 /**
  * Before previous migration execution hook.
  *
  * @return void
  */
 private function beforeDown()
 {
     $query = new Query();
     $migration = $query->select('*')->from('migrations')->where('version = ?', array($this->version))->first();
     if (!$migration) {
         $this->skip = true;
     }
 }
Example #2
0
 /**
  * Checks if a key-value pair exists.
  *
  * @param string $key Cache key.
  *
  * @return boolean
  */
 public function exists($key)
 {
     $query = new Query();
     $exists = $query->select('all')->from($this->tableName)->where("{$this->fields[0]} = ?", array(md5($key)))->exists();
     return $exists;
 }
Example #3
0
 /**
  * Get object/objects from the Database.
  *
  * @param string $fields List of fields to return (optional).
  *
  * @access public
  * @final
  * @static
  *
  * @return DB\Query
  */
 public static final function find($fields = 'all')
 {
     $query = new DB\Query(get_called_class());
     if (static::$isI18n) {
         if (!static::$i18nLocale) {
             $_locale = Core\Registry()->get('locale');
             static::$i18nLocale = isset(Core\Config()->I18N['locales'][$_locale]) ? $_locale : Core\Config()->I18N['default'];
         }
         if (!static::$i18nTableName) {
             static::$i18nTableName = static::$tableName . static::$i18nTableNameSuffix;
         }
         $prefix = Core\Config()->DB['tables_prefix'];
         return $query->select($fields)->from(static::$tableName)->join(static::$i18nTableName, $prefix . static::$tableName . '.' . static::$primaryKeyField . ' = ' . $prefix . static::$i18nTableName . '.' . static::$i18nForeignKeyField . ' AND ' . $prefix . static::$i18nTableName . '.' . static::$i18nLocaleField . ' = "' . static::$i18nLocale . '"');
     }
     return $query->select($fields)->from(static::$tableName);
 }
Example #4
0
 /**
  * Rollback method.
  *
  * @param integer $step Count of steps to rollback.
  *
  * @return void
  */
 public static function rollback($step = 1)
 {
     $query = new Query();
     $migrations_to_execute = $query->select('*')->from('migrations')->order('version', 'desc')->limit($step)->all();
     foreach ($migrations_to_execute as $item) {
         DB\Migrate::down($item['version']);
     }
 }
Example #5
0
 /**
  * Verifies whether a user owns a specific resource by resource data.
  *
  * @param mixed                 $resourceIds   Resource ID values.
  * @param string                $resourceModel Resource Model name.
  * @param \Core\Base\Model|null $owner         Owner instance to check.
  *
  * @access public
  * @static
  *
  * @return boolean Whether the user owns the resource or not.
  */
 public static function checkIds($resourceIds, $resourceModel, Base\Model $owner = null)
 {
     if (!$owner) {
         $owner = Core\Registry()->get('current_cms_user');
     }
     $result = false;
     $resourceIds = is_array($resourceIds) ? array_filter($resourceIds) : array($resourceIds);
     foreach ($resourceIds as $resourceId) {
         $query = new Core\Modules\DB\Query();
         $result = $query->select('owner_id')->from('cms_ownership')->where('resource_id = ? AND owner_id = ? AND model = ?', array($resourceId, $owner->getPrimaryKeyValue(), $resourceModel))->exists();
         if (!$result) {
             break;
         }
     }
     return $result;
 }