/**
  * Rename Table method
  *
  * @param string $type Type of operation to be done, this case 'rename_table'
  * @param array $tables List of tables to be renamed
  * @return boolean Return true in case of success, otherwise false
  * @access protected
  */
 protected function _renameTable($type, $tables)
 {
     foreach ($tables as $oldName => $newName) {
         $sources = $this->db->listSources();
         if (!in_array($oldName, $sources)) {
             throw new MigrationException($this, sprintf(__d('migrations', 'Table "%s" does not exists in database.', true), $oldName));
         } else {
             if (in_array($newName, $sources)) {
                 throw new MigrationException($this, sprintf(__d('migrations', 'Table "%s" already exists in database.', true), $newName));
             }
         }
         $sql = 'RENAME TABLE ' . $this->db->fullTableName($oldName) . ' TO ' . $this->db->fullTableName($newName) . ';';
         $this->_invokeCallbacks('beforeAction', 'rename_table', array('old_name' => $oldName, 'new_name' => $newName));
         if (@$this->db->execute($sql) === false) {
             throw new MigrationException($this, sprintf(__d('migrations', 'SQL Error: %s', true), $this->db->error));
         }
         $this->_invokeCallbacks('afterAction', 'rename_table', array('old_name' => $oldName, 'new_name' => $newName));
     }
     return true;
 }
示例#2
0
 /**
  * List available sources
  *
  * @return array of available CSV files
  */
 public function listSources()
 {
     $this->config['database'] = 'csv';
     $cache = parent::listSources();
     if ($cache !== null) {
         return $cache;
     }
     $extPattern = '\\.' . preg_quote($this->config['extension']);
     if ($this->config['recursive']) {
         $list = $this->connection->findRecursive('.*' . $extPattern, true);
         foreach ($list as &$item) {
             $item = mb_substr($item, mb_strlen($this->config['path'] . DS));
         }
     } else {
         $list = $this->connection->find('.*' . $extPattern, true);
     }
     foreach ($list as &$item) {
         $item = preg_replace('/' . $extPattern . '$/i', '', $item);
     }
     parent::listSources($list);
     unset($this->config['database']);
     return $list;
 }
示例#3
0
 /**
  * Caches/returns cached results for child instances.
  *
  * @param mixed $data List of tables
  * @return array Array of sources available in this datasource
  */
 public function listSources($data = null)
 {
     return parent::listSources($data);
 }
 /**
  * listSources
  * @param null $data
  * @return array|null
  */
 public function listSources($data = null)
 {
     return parent::listSources($data);
     // TODO: Change the autogenerated stub
 }
示例#5
0
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @param mixed $data
  * @return array Array of tablenames in the database
  */
 public function listSources($data = null)
 {
     $cache = parent::listSources();
     if ($cache !== null) {
         return $cache;
     }
 }
 /**
  * undocumented function
  *
  * @return void
  * @access public
  */
 function listSources($refresh = false)
 {
     if (!$this->connected() && !$this->login()) {
         return false;
     }
     $cache = parent::listSources();
     if (!$refresh && $cache != null) {
         return $cache;
     }
     $sources = array();
     $response = $this->Http->get('https://www.google.com/analytics/home/?et=reset&hl=en-US&ns=100');
     $optionsRegex = '/<option.+?value="([0-9]+)".*?>([^<]+)<\\/option>/si';
     preg_match('/<select.+?name="account_list".*?>(.+?)<\\/select>/is', $response, $accounts);
     if (empty($accounts)) {
         return false;
     }
     preg_match_all($optionsRegex, $accounts[1], $accounts, PREG_SET_ORDER);
     if (empty($accounts)) {
         return false;
     }
     foreach ($accounts as $i => $account) {
         list(, $id, $name) = $account;
         if (empty($id) || !is_numeric($id)) {
             continue;
         }
         $account = array('Account' => compact('id', 'name'));
         if ($i != 0) {
             $response = $this->Http->get('https://www.google.com/analytics/home/admin?scid=' . $id . '&ns=100');
         }
         preg_match('/<select.+?name="profile_list".*?>(.+?)<\\/select>/is', $response, $profiles);
         if (empty($profiles)) {
             $account['Profile'] = array();
             continue;
         }
         preg_match_all($optionsRegex, $profiles[1], $profiles, PREG_SET_ORDER);
         foreach ($profiles as $profile) {
             list(, $id, $name) = $profile;
             if (empty($id) || !is_numeric($id)) {
                 continue;
             }
             $account['Profile'][] = compact('id', 'name');
         }
         $sources[] = $account;
     }
     parent::listSources($sources);
     return $sources;
 }
示例#7
0
 /**
  * Lists all couchdb databases, and caches the response
  *
  * @param  array $data Data to be cached in parent call to DataSource::listSources().
  * @return array       Array of couchdb sources
  * @todo Move URI mangling to DivanSource::uri()
  */
 public function listSources($data = null)
 {
     $cache = parent::listSources($data);
     if ($cache != null) {
         return $cache;
     }
     $sources = $this->_decode($this->Socket->get($this->uri() . '_all_dbs'));
     parent::listSources($sources);
     return $sources;
 }