Files
EasySoft-ZenTaoPMS/module/convert/model.php
2012-02-21 07:22:58 +00:00

95 lines
2.8 KiB
PHP

<?php
/**
* The model file of convert module of ZenTaoPMS.
*
* @copyright Copyright 2009-2012 青岛易软天创网络科技有限公司 (QingDao Nature Easy Soft Network Technology Co,LTD www.cnezsoft.com)
* @license LGPL (http://www.gnu.org/licenses/lgpl.html)
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
* @package convert
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php
class convertModel extends model
{
/**
* Connect to db.
*
* @access public
* @return void
*/
public function connectDB()
{
$dsn = "mysql:host={$this->post->dbHost}; port={$this->post->dbPort};dbname={$this->post->dbName}";
try
{
$dbh = new PDO($dsn, $this->post->dbUser, $this->post->dbPassword);
$dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->exec("SET NAMES {$this->post->dbCharset}");
$this->sourceDBH = $dbh;
return $dbh;
}
catch (PDOException $exception)
{
return $exception->getMessage();
}
}
/**
* Check database exits or not.
*
* @access public
* @return bool
*/
public function dbExists()
{
$sql = "SHOW DATABASES like '{$this->post->db->name}'";
return $this->dbh->query($sql)->fetch();
}
/**
* Check table exits or not.
*
* @access public
* @return bool
*/
public function tableExists($table)
{
$sql = "SHOW tables like '$table'";
return $this->dbh->query($sql)->fetch();
}
/**
* Save the max id of every table. Thus when we convert again, when can delete id larger then the saved max id.
*
* @access public
* @return void
*/
public function saveState()
{
/* Get user defined tables. */
$constants = get_defined_constants(true);
$userConstants = $constants['user'];
/* These tables needn't save. */
unset($userConstants['TABLE_BURN']);
unset($userConstants['TABLE_GROUPPRIV']);
unset($userConstants['TABLE_PROJECTPRODUCT']);
unset($userConstants['TABLE_PROJECTSTORY']);
unset($userConstants['TABLE_STORYSPEC']);
unset($userConstants['TABLE_TEAM']);
unset($userConstants['TABLE_USERGROUP']);
/* Get max id of every table. */
foreach($userConstants as $key => $value)
{
if(strpos($key, 'TABLE') === false) continue;
if($key == 'TABLE_COMPANY') continue;
$state[$value] = (int)$this->dao->select('MAX(id) AS id')->from($value)->fetch('id');
}
$this->session->set('state', $state);
}
}