Example #1
0
 /**
  * Rename database table
  *
  * @param string $newName
  *          - new table name (without prefix)
  * @return boolean
  * @throws Exception
  */
 public function renameTable($newName)
 {
     if ($this->_objectConfig->isLocked() || $this->_objectConfig->isReadOnly()) {
         $this->_errors[] = 'Can not build locked object ' . $this->_objectConfig->getName();
         return false;
     }
     $store = Store_Local::getInstance();
     $sql = 'RENAME TABLE `' . $this->_model->table() . '` TO `' . $this->_model->getDbPrefix() . $newName . '` ;';
     try {
         $this->_db->query($sql);
         $this->_logSql($sql);
         $this->_objectConfig->getConfig()->set('table', $newName);
         $this->_model->refreshTableInfo();
         return true;
     } catch (Exception $e) {
         $this->_errors[] = $e->getMessage() . ' <br>SQL: ' . $sql;
         return false;
     }
 }