Source for file tangra_module_uninstaller.class.php
Documentation is available at tangra_module_uninstaller.class.php
// *** Tangra framework for php
* Contains class Tangra_Module_Uninstaller
* @subpackage modules_manager
require_once(TANGRA_MAIN_DIR. 'filesystem_toolbox/filesystem_functions.inc.php');
* Tangra_Module_Uninstaller is the base class used by all module installers
* @subpackage modules_manager
* Parameter $params is a structured array that must have at least key 'module-conf-path'. Other parameters have to be fed as key-value pairs.
* Example $params[''module-conf-path'] = '/some/path';
$hidden_start = strpos($params['module-conf-path'], 'hidden/conf');
if ($hidden_start !== false) {
* Performs uninstall of the module
$ret = array('ok' => true, 'removed_files' => array(), 'removed_db_objects' => array());
* Checks if parameter is present
* @param string $parameter Parameter to be checked
* @param string $module_conf_path
throw new TE_TMM_Exception('Path does not exist or it is not a directory: '. $module_conf_path);
* @param DB_Connection $dbc
public function set_dbc( DB_Connection $dbc) {
* Checks if all required parameters are present
* @throws TE_TMM_Exception
if (!$params['module-conf-path']) {
throw new TE_TMM_Exception('$params[module-conf-path] is empty.');
throw new TE_TMM_Exception('$params[module-conf-path] is not passed.');
$files = file($module_files_list);
* Prepares list of files to be removed expanding paths to full paths
* Can handle with files.list with releative paths
* @param array $files_list
foreach($files_list as $item) {
if (strpos($item, '%') !== false) {
$item = str_replace('%HIDDEN%', $site_dirs['hidden'], $item);
$item = str_replace('%HTDOCS%', $site_dirs['htdocs'], $item);
$item = str_replace('%EXT_INC%', $site_dirs['ext_inc'], $item);
$item = str_replace('%SCRATCH%', $site_dirs['scratch'], $item);
$space_pos = strpos($item, ' ');
if ($space_pos !== false) {
$item = substr($item, 0, $space_pos);
// processing old style files.list (i.e. with full paths or relative without root dir)
$space_pos = strpos($item, ' ');
if ($space_pos !== false) {
if (substr($item, 0, 1) == '/') {
$ret[] = substr($item, 0, $space_pos);
if (substr($item, 0, 1) == '/') {
foreach($files_list as $item) {
$ret['freed'] = $used_space;
* Removes DB objects - tables and/or columns
$file = $module_conf_path. 'uninstall_db_items.txt';
if ($e instanceof TE_DBC_SQL_Failed) {
* Generates SQL for drop column
* @return string SQL Drop column statement
$ret = "ALTER TABLE $table DROP COLUMN '$column'";
* Loads hidden, htdocs, scratch and ext_inc paths and returns them as array
* @param string $root_dir Path to site's root dir
$root_dir = substr($module_conf_path, 0, strpos($module_conf_path, 'hidden/conf/modules/'));
$root_dir = substr($module_conf_path, 0, strpos($module_conf_path, 'hidden/conf/modules/')); // just in case path is not normalized
$ms_conf = $root_dir. 'hidden/conf/machine_specific.conf';
$ms_conf = $root_dir. 'hidden/conf/machine_specific.conf';
$hidden_dir = $conf_loader->get_conf_value('HIDDEN', false);
$hidden_dir = $root_dir. 'hidden/';
$htdocs_dir = $conf_loader->get_conf_value('DOCUMENT_ROOT', false);
$htdocs_dir = $root_dir. 'htdocs/';
$scratch_dir = $conf_loader->get_conf_value('SCRATCH', false);
$scratch_dir = $root_dir. 'scratch/';
$ext_inc_dir = $conf_loader->get_conf_value('EXT_INC', false);
$ext_inc_dir = $root_dir. 'ext_inc/';
return array('hidden' => $hidden_dir, 'htdocs' => $htdocs_dir, 'scratch' => $scratch_dir, 'ext_inc' => $ext_inc_dir);
|