Пример #1
0
 function getChannel()
 {
     if (isset($this->_packagefile)) {
         return $this->_packagefile->getChannel();
     } elseif (isset($this->_downloadURL['info'])) {
         return $this->_downloadURL['info']->getChannel();
     }
     return false;
 }
Пример #2
0
 /**
 * @param array $xml contents of postinstallscript tag
 *  example: Array (
            [paramgroup] => Array (
                [id] => webSetup
                [param] => Array (
                    [name] => webdirpath
                    [prompt] => Where should... ?
                    [default] => '/var/www/htdocs/webpear
                    [type] => string
                    )
                )
            )
 * @param object $script post-installation script
 * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2 $pkg
 * @param string $contents contents of the install script
 */
 function runInstallScript($xml, &$script, &$pkg)
 {
     if (!isset($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'])) {
         $_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'] = array();
         $_SESSION['_PEAR_Frontend_Web_ScriptSkipSections'] = array();
     }
     if (isset($_SESSION['_PEAR_Frontend_Web_ScriptObj'])) {
         foreach ($_SESSION['_PEAR_Frontend_Web_ScriptObj'] as $name => $val) {
             if ($name[0] == '_') {
                 // only public variables will be restored
                 continue;
             }
             $script->{$name} = $val;
         }
     } else {
         $_SESSION['_PEAR_Frontend_Web_ScriptObj'] = (array) $script;
     }
     if (!is_array($xml) || !isset($xml['paramgroup'])) {
         $script->run(array(), '_default');
     } else {
         if (!isset($xml['paramgroup'][0])) {
             $xml['paramgroup'] = array($xml['paramgroup']);
         }
         foreach ($xml['paramgroup'] as $i => $group) {
             if (isset($_SESSION['_PEAR_Frontend_Web_ScriptSkipSections'][$group['id']])) {
                 continue;
             }
             if (isset($_SESSION['_PEAR_Frontend_Web_ScriptSection'])) {
                 if ($i < $_SESSION['_PEAR_Frontend_Web_ScriptSection']) {
                     $lastgroup = $group;
                     continue;
                 }
             }
             if (isset($_SESSION['_PEAR_Frontend_Web_answers'])) {
                 $answers = $_SESSION['_PEAR_Frontend_Web_answers'];
             }
             if (isset($group['name'])) {
                 if (isset($answers)) {
                     if (isset($answers[$group['name']])) {
                         switch ($group['conditiontype']) {
                             case '=':
                                 if ($answers[$group['name']] != $group['value']) {
                                     continue 2;
                                 }
                                 break;
                             case '!=':
                                 if ($answers[$group['name']] == $group['value']) {
                                     continue 2;
                                 }
                                 break;
                             case 'preg_match':
                                 if (!@preg_match('/' . $group['value'] . '/', $answers[$group['name']])) {
                                     continue 2;
                                 }
                                 break;
                             default:
                                 $this->_clearScriptSession();
                                 return;
                         }
                     }
                 } else {
                     $this->_clearScriptSession();
                     return;
                 }
             }
             if (!isset($group['param'][0])) {
                 $group['param'] = array($group['param']);
             }
             $_SESSION['_PEAR_Frontend_Web_ScriptSection'] = $i;
             if (!isset($answers)) {
                 $answers = array();
             }
             if (isset($group['param'])) {
                 if (method_exists($script, 'postProcessPrompts')) {
                     $prompts = $script->postProcessPrompts($group['param'], $group['name']);
                     if (!is_array($prompts) || count($prompts) != count($group['param'])) {
                         $this->outputData('postinstall', 'Error: post-install script did not ' . 'return proper post-processed prompts');
                         $prompts = $group['param'];
                     } else {
                         foreach ($prompts as $i => $var) {
                             if (!is_array($var) || !isset($var['prompt']) || !isset($var['name']) || $var['name'] != $group['param'][$i]['name'] || $var['type'] != $group['param'][$i]['type']) {
                                 $this->outputData('postinstall', 'Error: post-install script ' . 'modified the variables or prompts, severe security risk. ' . 'Will instead use the defaults from the package.xml');
                                 $prompts = $group['param'];
                             }
                         }
                     }
                     $answers = array_merge($answers, $this->confirmDialog($prompts, $pkg->getChannel() . '/' . $pkg->getPackage()));
                 } else {
                     $answers = array_merge($answers, $this->confirmDialog($group['param'], $pkg->getChannel() . '/' . $pkg->getPackage()));
                 }
             }
             if ($answers) {
                 array_unshift($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'], $group['id']);
                 if (!$script->run($answers, $group['id'])) {
                     $script->run($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'], '_undoOnError');
                     $this->_clearScriptSession();
                     return;
                 }
             } else {
                 $script->run(array(), '_undoOnError');
                 $this->_clearScriptSession();
                 return;
             }
             $lastgroup = $group;
             foreach ($group['param'] as $param) {
                 // rename the current params to save for future tests
                 $answers[$group['id'] . '::' . $param['name']] = $answers[$param['name']];
                 unset($answers[$param['name']]);
             }
             // save the script's variables and user answers for the next round
             $_SESSION['_PEAR_Frontend_Web_ScriptObj'] = (array) $script;
             $_SESSION['_PEAR_Frontend_Web_answers'] = $answers;
             $_SERVER['REQUEST_METHOD'] = '';
         }
     }
     $this->_clearScriptSession();
 }