<?php
if(!defined('XOOPS_ROOT_PATH'))exit();

require_once XOOPS_ROOT_PATH.'/modules/legacy/admin/class/ModuleUninstaller.class.php';
require_once XOOPS_TRUST_PATH . '/modules/xdbmigrate/admin/class/installer/XdbmigrateInstallUtils.class.php';
class Xdbmigrate_Uninstaller extends Legacy_ModuleUninstaller
{
  function __construct() {
    parent::Legacy_ModuleUninstaller();
  }
  
  function _uninstallTables()
  {
      $root =& XCube_Root::getSingleton();
      $db =& $root->mController->getDB();
      $dirname = $this->_mXoopsModule->get('dirname');

      $tables =& $this->_mXoopsModule->getInfo('tables');
      if(is_array($tables))
      {
            foreach($tables as $table)
            {
            	/*
                $tableName = str_replace(
                    array('{prefix}','{dirname}'),
                    array(XOOPS_DB_PREFIX,$dirname),
                    $table
                );
                */
                $tableName = $db->prefix($table);
                $sql = sprintf('drop table `%s`;',$tableName);
                
                if($db->query($sql))
                {
                    $this->mLog->addReport(
                        XCube_Utils::formatString(
                            _MI_XDBMIGRATE_INSTALL_MSG_TABLE_DOROPPED,
                            $tableName
                        )
                    );
                }
                else
                {
                    $this->mLog->addError(
                        XCube_Utils::formatString(
                            _MI_XDBMIGRATE_INSTALL_ERROR_TABLE_DOROPPED,
                            $tableName
                        )
                    );
                }
            }
        }
    }
};
