コード例 #1
0
 /**
  * plugin uninstaller with best effort depending on what it finds.
  *
  * @param  int     $id
  * @param  string  $option
  * @param  int     $client
  * @param  string  $action
  * @return boolean
  */
 function uninstall($id, $option, $client = 0)
 {
     global $_CB_database;
     $db = false;
     if ($this->checkPluginGetXml($id, $option, $client)) {
         if ($this->i_xmldocument !== null && count($this->i_xmldocument->children()) > 0) {
             $cbInstallXML =& $this->i_xmldocument;
             // get the element name:
             $e =& $cbInstallXML->getElementByPath('name');
             $this->elementName($e->data());
             // $cleanedElementName = strtolower(str_replace(array(" ","."),array("","_"),$this->elementName()));
             // get the files element
             $files_element =& $cbInstallXML->getElementByPath('files');
             if ($files_element) {
                 if (count($files_element->children())) {
                     foreach ($files_element->children() as $file) {
                         if ($file->attributes("plugin")) {
                             $this->elementSpecial($file->attributes("plugin"));
                             break;
                         }
                     }
                     $cleanedMainFileName = strtolower(str_replace(array(" ", "."), array("", "_"), $this->elementSpecial()));
                 }
                 // Is there an uninstallfile
                 $uninstallfile_elemet =& $cbInstallXML->getElementByPath('uninstallfile');
                 if ($uninstallfile_elemet !== false) {
                     if (is_file($this->i_elementdir . $uninstallfile_elemet->data())) {
                         global $_PLUGINS;
                         // needed for the require_once below !
                         require_once $this->i_elementdir . $uninstallfile_elemet->data();
                         $ret = call_user_func_array("plug_" . $cleanedMainFileName . "_uninstall", array());
                         if ($ret != '') {
                             $this->setError(0, $ret);
                         }
                     }
                 }
                 $adminFS =& cbAdminFileSystem::getInstance();
                 foreach ($files_element->children() as $file) {
                     // delete the files
                     $filename = $file->data();
                     if (file_exists($this->i_elementdir . $filename)) {
                         $parts = pathinfo($filename);
                         $subpath = $parts['dirname'];
                         if ($subpath != '' && $subpath != '.' && $subpath != '..') {
                             //echo '<br />'. 'Deleting'  .': '. $this->i_elementdir . $subpath;
                             $result = $adminFS->deldir(_cbPathName($this->i_elementdir . $subpath . '/'));
                         } else {
                             //echo '<br />'. 'Deleting'  .': '. $this->i_elementdir . $filename;
                             $result = $adminFS->unlink(_cbPathName($this->i_elementdir . $filename, false));
                         }
                         //echo intval( $result );
                     }
                 }
                 // Are there any SQL queries??
                 $query_element =& $cbInstallXML->getElementByPath('uninstall/queries');
                 if ($query_element !== false) {
                     foreach ($query_element->children() as $query) {
                         $_CB_database->setQuery(trim($query->data()));
                         if (!$_CB_database->query()) {
                             $this->setError(1, "SQL Error " . $_CB_database->stderr(true));
                             return false;
                         }
                     }
                 }
                 // Are there any Database statements ??
                 $db =& $cbInstallXML->getElementByPath('database');
                 if ($db !== false && count($db->children()) > 0) {
                     cbimport('cb.sql.upgrader');
                     $sqlUpgrader = new CBSQLupgrader($_CB_database, false);
                     //$sqlUpgrader->setDryRun( true );
                     $success = $sqlUpgrader->checkXmlDatabaseDescription($db, $cleanedMainFileName, 'drop', null);
                     /*
                     var_dump( $success );
                     echo "<br>\nERRORS: " . $sqlUpgrader->getErrors( "<br /><br />\n\n", "<br />\n" );
                     echo "<br>\nLOGS: " . $sqlUpgrader->getLogs( "<br /><br />\n\n", "<br />\n" );
                     exit;
                     */
                     if (!$success) {
                         $this->setError(1, "Plugin database XML SQL Error " . $sqlUpgrader->getErrors());
                         return false;
                     }
                 }
                 // Delete tabs and private fields of plugin:
                 $this->deleteTabAndFieldsOfPlugin($id);
                 // remove XML file from front
                 $xmlRemoveResult = $adminFS->unlink(_cbPathName($this->i_installfilename, false));
                 $filesRemoveResult = true;
                 /*					// define folders that should not be removed
                 					$sysFolders = array(
                 					'content',
                 					'search'
                 					);
                 					if ( ! in_array( $row->folder, $sysFolders ) ) {
                 */
                 // delete the non-system folders if empty
                 if (count(cbReadDirectory($this->i_elementdir)) < 1) {
                     $filesRemoveResult = $adminFS->deldir($this->i_elementdir);
                 }
                 /*					}
                 */
                 if (!$xmlRemoveResult) {
                     HTML_comprofiler::showInstallMessage('Could not delete XML file: ' . _cbPathName($this->i_installfilename, false) . ' due to permission error. Please remove manually.', 'Uninstall -  warning', $this->returnTo($option, 'showPlugins'));
                 }
                 if (!$filesRemoveResult) {
                     HTML_comprofiler::showInstallMessage('Could not delete directory: ' . $this->i_elementdir . ' due to permission error. Please remove manually.', 'Uninstall -  warning', $this->returnTo($option, 'showPlugins'));
                 }
             }
         }
         $_CB_database->setQuery("DELETE FROM #__comprofiler_plugin WHERE id = " . (int) $id);
         if (!$_CB_database->query()) {
             $msg = $_CB_database->stderr;
             HTML_comprofiler::showInstallMessage('Cannot delete plugin database entry due to error: ' . $msg, 'Uninstall -  error', $this->returnTo($option, 'showPlugins'));
             return false;
         }
         if ($this->i_xmldocument !== null && $db !== false && count($db->children()) > 0) {
             HTML_comprofiler::fixcbdbShowResults($sqlUpgrader, true, false, $success, array(), array(), $this->elementName(), 1, false);
         }
         return true;
     }
     return false;
 }
コード例 #2
0
function fixcbdb($dryRun, $dbId = 0)
{
    global $_CB_database, $ueConfig, $_PLUGINS;
    // Try extending time, as unziping/ftping took already quite some... :
    @set_time_limit(240);
    $dryRun = $dryRun == 1;
    if ($dbId == 0) {
        $dbName = CBTxt::T('Core CB');
        // Fix mandatory basics of core CB:
        cbimport('cb.dbchecker');
        $dbChecker = new CBdbChecker($_CB_database);
        $result = $dbChecker->checkCBMandatoryDb(true, $dryRun);
        $dbName = CBTxt::T('Core CB mandatory basics');
        $messagesAfter = array();
        $messagesBefore = array();
        ob_start();
        HTML_comprofiler::fixcbdbShowResults($dbChecker, true, $dryRun, $result, $messagesBefore, $messagesAfter, $dbName, $dbId);
        $html = ob_get_contents();
        ob_end_clean();
        // Fix core CB:
        $_PLUGINS->loadPluginGroup('user');
        $messagesBefore = $_PLUGINS->trigger('onBeforeFixDb', array($dryRun));
        $messagesBefore[] = $html;
        $dbName = CBTxt::T('Core CB');
        $dbChecker = new CBdbChecker($_CB_database);
        $result = $dbChecker->checkDatabase(true, $dryRun);
        $messagesAfter = $_PLUGINS->trigger('onAfterFixDb', array($dryRun));
        // adapt published fields to global CB config (regarding name type)
        _cbAdaptNameFieldsPublished($ueConfig);
    } elseif ($dbId == 1) {
        // Fix plugin $dbId:
        $dbName = CBTxt::T('CB plugin');
        $messagesBefore = array();
        $messagesAfter = array();
        cbimport('cb.installer');
        $sql = 'SELECT `id`, `name` FROM `#__comprofiler_plugin` ORDER BY `ordering`';
        $_CB_database->setQuery($sql);
        $plugins = $_CB_database->loadObjectList();
        if (!$_CB_database->getErrorNum()) {
            $cbInstaller = new cbInstallerPlugin();
            foreach ($plugins as $plug) {
                $result = $cbInstaller->checkDatabase($plug->id, true, $dryRun);
                if (is_bool($result)) {
                    HTML_comprofiler::fixcbdbShowResults($cbInstaller, true, $dryRun, $result, $messagesBefore, $messagesAfter, $dbName . ' "' . $plug->name . '"', $dbId, false);
                } elseif (is_string($result)) {
                    echo '<div style="color:orange;">' . $dbName . ' "' . $plug->name . '"' . ': ' . $result . '</div>';
                } else {
                    echo '<div style="color:black;">' . sprintf(CBTxt::T('%s "%s": no database or no database description.'), $dbName, $plug->name) . '</div>';
                }
            }
        }
        $dbName = CBTxt::T('CB plugins');
    } elseif ($dbId == 3) {
        // adapt published fields to global CB config (regarding name type)
        _cbAdaptNameFieldsPublished($ueConfig);
        $_PLUGINS->loadPluginGroup('user');
        $messagesBefore = $_PLUGINS->trigger('onBeforeFixFieldsDb', array($dryRun));
        // Check fields db:
        cbimport('cb.dbchecker');
        $dbChecker = new CBdbChecker($_CB_database);
        $result = $dbChecker->checkAllCBfieldsDb(true, $dryRun);
        $dbName = CBTxt::T('CB fields data storage');
        $messagesAfter = array();
    }
    HTML_comprofiler::secureAboveForm('fixcbdb');
    outputCbTemplate(2);
    outputCbJs(2);
    global $_CB_Backend_Title;
    $_CB_Backend_Title = array(0 => array('cbicon-48-tools', sprintf(CBTxt::T("CB Tools: Fix %s database: "), $dbName) . ($dryRun ? CBTxt::T('Dry-run:') : CBTxt::T('Fixed:')) . " " . CBTXT::T("Results")));
    HTML_comprofiler::fixcbdbShowResults($dbChecker, true, $dryRun, $result, $messagesBefore, $messagesAfter, $dbName, $dbId);
}