function test_upgradeConfig()
 {
     $oPkgMgr = new OX_PluginManager();
     $zipFile = $this->aUpload['tmp_name'];
     // version 2 package should be installed
     // put the version 3 package in place
     $this->_switchFiles(3);
     $this->assertTrue($oPkgMgr->_checkPackageContents($this->packageName . '.xml', $zipFile, true));
     $aPlugin = $oPkgMgr->aParse['plugins'][1];
     $this->assertEqual($aPlugin['version'], '0.0.3');
     // Test 2 : upgrade to version 0.0.3 ; this involves 0 upgrade or schema packages, just a version stamp
     $oUpgrader = new OX_Plugin_UpgradeComponentGroup($aPlugin, $oPkgMgr);
     $this->assertTrue($oUpgrader->canUpgrade());
     $this->assertEqual($oUpgrader->existing_installation_status, OA_STATUS_CAN_UPGRADE);
     // decompress the zip file, 2nd param indicates overwrite previous files
     $oPkgMgr->_unpack($this->aUpload, true);
     // now that the files are in place, the upgrader can do a schema integrity check
     $this->assertTrue($oUpgrader->canUpgrade());
     $this->assertEqual($oUpgrader->existing_installation_status, OA_STATUS_CAN_UPGRADE);
     $this->assertEqual(count($oUpgrader->aPackageList), 0);
     $aConf =& $GLOBALS['_MAX']['CONF'][$aPlugin['name']];
     // _upgradeConfig calls _upgradeSettings() and _upgradePreferences
     // Test 1 Settings
     // set non-default settings
     $aConf['setting1'] = 'testval1';
     $aConf['setting2'] = 'testval2';
     $aConf['setting3'] = 'testval3';
     $this->assertTrue($oUpgrader->_upgradeSettings());
     // old settings should have original values
     // new setting should have default value
     // deprecated setting should no longer exist
     $aConf =& $GLOBALS['_MAX']['CONF'][$aPlugin['name']];
     $this->assertEqual(count($aConf), 3);
     $this->assertEqual($aConf['setting1'], 'testval1');
     $this->assertEqual($aConf['setting2'], 'testval2');
     $this->assertFalse(isset($aConf['setting3']));
     $this->assertEqual($aConf['setting4'], 'setval4');
     // Test 2 Preferences
     $oDbh = OA_DB::singleton();
     $qryPrefs = 'preference_name LIKE ' . $oDbh->quote('%' . $prefix . '%');
     $prefix = $aPlugin['name'] . '_';
     $doPreferences = OA_Dal::factoryDO('preferences');
     $doPreferences->whereAdd($qryPrefs);
     $doPreferences->find();
     while ($doPreferences->fetch()) {
         $doAccount_Preference_Assoc = OA_Dal::factoryDO('account_preference_assoc');
         $doAccount_Preference_Assoc->whereAdd('preference_id = ' . $doPreferences->preference_id);
         $aPrefsOld[$doPreferences->preference_name] = array('permission' => $doPreferences->account_type, 'id' => $doPreferences->preference_id, 'acct_assoc' => $doAccount_Preference_Assoc->getAll());
     }
     $this->assertEqual(count($aPrefsOld), 2);
     $this->assertFalse(isset($aPrefsOld[$prefix . 'preference3']));
     $this->assertTrue(isset($aPrefsOld[$prefix . 'preference1']));
     $this->assertTrue(isset($aPrefsOld[$prefix . 'preference2']));
     $this->assertEqual($aPrefsOld[$prefix . 'preference1']['permission'], 'MANAGER');
     $this->assertEqual($aPrefsOld[$prefix . 'preference2']['permission'], 'ADMIN');
     $this->assertTrue(isset($aPrefsOld[$prefix . 'preference1']['acct_assoc']));
     $this->assertTrue(isset($aPrefsOld[$prefix . 'preference2']['acct_assoc']));
     $this->assertEqual($aPrefsOld[$prefix . 'preference1']['acct_assoc'][0]['account_id'], '0');
     $this->assertEqual($aPrefsOld[$prefix . 'preference2']['acct_assoc'][0]['account_id'], '0');
     $this->assertTrue($oUpgrader->_upgradePreferences());
     $doPreferences = OA_Dal::factoryDO('preferences');
     $doPreferences->whereAdd($qryPrefs);
     $doPreferences->find();
     while ($doPreferences->fetch()) {
         $doAccount_Preference_Assoc = OA_Dal::factoryDO('account_preference_assoc');
         $doAccount_Preference_Assoc->whereAdd('preference_id = ' . $doPreferences->preference_id);
         $aPrefsNew[$doPreferences->preference_name] = array('permission' => $doPreferences->account_type, 'id' => $doPreferences->preference_id, 'acct_assoc' => $doAccount_Preference_Assoc->getAll());
     }
     $this->assertEqual(count($aPrefsNew), 2);
     $this->assertFalse(isset($aPrefsNew[$prefix . 'preference2']));
     $this->assertTrue(isset($aPrefsNew[$prefix . 'preference1']));
     $this->assertTrue(isset($aPrefsNew[$prefix . 'preference3']));
     $this->assertEqual($aPrefsNew[$prefix . 'preference1']['permission'], 'MANAGER');
     $this->assertEqual($aPrefsNew[$prefix . 'preference3']['permission'], 'ADMIN');
     $this->assertTrue(isset($aPrefsNew[$prefix . 'preference1']['acct_assoc']));
     $this->assertTrue(isset($aPrefsNew[$prefix . 'preference3']['acct_assoc']));
     $this->assertEqual($aPrefsNew[$prefix . 'preference1']['acct_assoc'][0]['account_id'], '0');
     $this->assertEqual($aPrefsNew[$prefix . 'preference3']['acct_assoc'][0]['account_id'], '0');
     $doAccount_Preference_Assoc = OA_Dal::factoryDO('account_preference_assoc');
     $doAccount_Preference_Assoc->preference_id = $aPrefsOld['testPlugin_preference2']['id'];
     $this->assertFalse($doAccount_Preference_Assoc->find());
     $oPkgMgr->uninstallPackage($this->packageName);
 }
 function test_getPackageDiagnostics()
 {
     $oPkgMgr = new OX_PluginManager();
     $file = MAX_PATH . $this->testpathData . 'zipDiagnosticTest/testPluginPackage.zip';
     unset($GLOBALS['_MAX']['CONF']['plugins']['testPluginPackage']);
     unset($GLOBALS['_MAX']['CONF']['pluginGroupComponents']['testPlugin001']);
     //install
     $this->assertTrue($oPkgMgr->installPackage(array('tmp_name' => $file, 'name' => 'testPluginPackage.zip')));
     if (count($oPkgMgr->aErrors)) {
         foreach ($oPkgMgr->aErrors as $error) {
             $this->fail($error);
         }
     }
     $aResultGood = $oPkgMgr->getPackageDiagnostics('testPluginPackage');
     $this->assertFalse($aResultGood['plugin']['error']);
     unlink(MAX_PATH . $oPkgMgr->pathPluginsAdmin . 'testPlugin001/' . 'testPlugin-common.php');
     $oPkgMgr->_unregisterSettings('testPlugin001', false);
     unset($GLOBALS['_MAX']['CONF']['testPlugin001']);
     unset($GLOBALS['_MAX']['CONF']['testPlugin001']['setting1']);
     $oPkgMgr->_unregisterPluginVersion('testPlugin001');
     $oPkgMgr->_unregisterSchemaVersion('testPlugin001');
     $oPkgMgr->_unregisterPreferences('testPlugin001', $aResultGood['groups'][0]['install']['config']['preferences']);
     $oPkgMgr->_dropTables('testPlugin', $aResultGood['groups'][0]['install']['database']['mdb2schema']);
     $aResultBad = $oPkgMgr->getPackageDiagnostics('testPluginPackage');
     $this->assertTrue($aResultBad['groups'][1]['error']);
     //uninstall
     $this->assertTrue($oPkgMgr->uninstallPackage('testPluginPackage'));
     TestEnv::restoreConfig();
 }
Beispiel #3
0
 if ('uninstall' == $action) {
     $oTpl = new OA_Admin_Template('plugin-uninstall.html');
     $aPackageInfo = $oPluginManager->getPackageInfo($plugin);
     $aComponents = $aPackageInfo['contents'];
     unset($aPackageInfo['contents']);
     if ($aPackageInfo['uninstallReadme']) {
         $uninstallReadme = file_get_contents($aPackageInfo['uninstallReadme']);
     }
     $aPackageInfo['package'] = true;
     $oTpl->assign('aPackage', $aPackageInfo);
     $oTpl->assign('aPlugins', $aComponents);
     $oTpl->assign('uninstallReadme', $uninstallReadme);
     $oTpl->assign('backURL', MAX::constructURL(MAX_URL_ADMIN, "plugin-index.php?selection=packages"));
 } else {
     if (array_key_exists('uninstallConfirmed', $_POST)) {
         $oPluginManager->uninstallPackage($plugin);
         if (!($oPluginManager->countErrors() || $oPluginManager->countWarnings())) {
             OX_Admin_Redirect::redirect('plugin-index.php');
         }
     } else {
         if ('enable' == $action) {
             if ($plugin) {
                 $oPluginManager->enablePackage($plugin);
             }
             if (!($oPluginManager->countErrors() || $oPluginManager->countWarnings())) {
                 OX_Admin_Redirect::redirect('plugin-index.php');
             }
         } else {
             if ('disable' == $action) {
                 if ($plugin) {
                     $oPluginManager->disablePackage($plugin);
/**
 * A function to remove the configiration setup for any plugins that were found
 * in the previous installation before upgrade, but which have been marked as
 * deprecated plugins.
 *
 * @param string $pluginName The name of the plugin to remove.
 * @return array An array of the 'name', 'status' and any 'errors' as an array.
 */
function removePlugin($pluginName)
{
    $aErrors = array();
    $aResult = array('name' => $pluginName, 'status' => '', 'errors' => &$aErrors);
    if (array_key_exists($pluginName, $GLOBALS['_MAX']['CONF']['plugins'])) {
        require_once RV_PATH . '/lib/RV.php';
        require_once MAX_PATH . '/lib/OA.php';
        require_once LIB_PATH . '/Plugin/PluginManager.php';
        $oPluginManager = new OX_PluginManager();
        $result = $oPluginManager->uninstallPackage($pluginName, true);
        if ($result) {
            $aResult['status'] = '<br />Uninstalled';
        } else {
            $aResult['status'] = '<br />Error';
            $aErrors[] = 'Problems found with plugin ' . $pluginName . '. The plugin was found in the previous installation' . ' and has been marked as deprecated, but was unable to' . ' be removed. Please go to the Configuration Plugins page' . ' and remove it.';
        }
    } else {
        $aResult['status'] = '<br />OK; Not installed';
        $aErrors[] = 'Problems found with plugin ' . $pluginName . '. The plugin was found in the previous installation' . ' and has been marked as deprecated, but was then not' . ' found as being installed when attempting to remove it.' . ' Please go to the Configuration Plugins page to ensure' . ' it is not installed.';
    }
    return $aResult;
}