/**
  * {@inheritdoc}
  */
 public function handle(\Input $input)
 {
     if (Runtime::clearComposerCache()) {
         $_SESSION['TL_CONFIRM'][] = $GLOBALS['TL_LANG']['composer_client']['composerCacheCleared'];
     }
     $this->redirect('contao/main.php?do=composer');
 }
 /**
  * {@inheritdoc}
  */
 public function handle(\Input $input)
 {
     if (Runtime::clearComposerCache()) {
         Messages::addConfirmation($GLOBALS['TL_LANG']['composer_client']['composerCacheCleared']);
     }
     $this->redirect('contao/main.php?do=composer');
 }
 /**
  * Test the readComposerDevWarningTime
  *
  * @return boolean
  *
  * @dataProvider providerReadComposerDevWarningTime
  */
 public function testReadComposerDevWarningTime($expected, $testArg)
 {
     $tempFile = tmpfile();
     fwrite($tempFile, str_repeat(PHP_EOL, 10) . $testArg . str_repeat(PHP_EOL, 10));
     fseek($tempFile, 0);
     $actual = Runtime::readComposerDevWarningTimeFromStream($tempFile);
     fclose($tempFile);
     $this->assertEquals($expected, $actual);
 }
 /**
  * Download an url and return or store contents.
  *
  * @param string $url
  * @param bool   $file
  *
  * @return bool|null|string
  * @throws \Exception
  */
 public static function download($url, $file = false)
 {
     if (Runtime::isCurlEnabled()) {
         return static::curlDownload($url, $file);
     } else {
         if (Runtime::isAllowUrlFopenEnabled()) {
             return static::fgetDownload($url, $file);
         } else {
             throw new \RuntimeException('No download mechanism available');
         }
     }
 }
 /**
  * Load composer and the composer class loader.
  */
 protected function loadComposer()
 {
     // search for composer build version
     $composerDevWarningTime = Runtime::readComposerDevWarningTime();
     $incompatibleVersion = false === $composerDevWarningTime || mktime(11, 0, 0, 6, 5, 2014) > $composerDevWarningTime - 30 * 86400;
     // Update if allowed or composer version is incompatible.
     if ($incompatibleVersion || $GLOBALS['TL_CONFIG']['composerAutoUpdateLibrary'] && time() > $composerDevWarningTime) {
         Runtime::updateComposer();
         Messages::addConfirmation($GLOBALS['TL_LANG']['composer_client']['composerUpdated']);
     }
     if ($composerDevWarningTime && !$GLOBALS['TL_CONFIG']['composerAutoUpdateLibrary'] && $incompatibleVersion) {
         Messages::addError($GLOBALS['TL_LANG']['composer_client']['composerUpdateNecessary']);
     }
     // register composer class loader
     Runtime::registerComposerClassLoader();
     // define pathname to config file
     $this->configPathname = COMPOSER_DIR_RELATIVE . '/' . Factory::getComposerFile();
     // create io interface
     $this->io = new BufferIO('', $this->getDebugLevel(), new HtmlOutputFormatter());
     // create composer
     $this->composer = Runtime::createComposer($this->io);
 }
Beispiel #6
0
    trigger_error('Composer client requires PHP 5.3, even with Contao 2.11', E_USER_ERROR);
    return;
}
if (version_compare(VERSION, '3', '<')) {
    include TL_ROOT . '/system/modules/!composer/src/ClassLoader.php';
    \ContaoCommunityAlliance\Contao\Composer\ClassLoader::register();
    spl_autoload_register('__autoload');
    \Contao2ClassFileExistsHack::register();
}
define('COMPOSER_MIN_PHPVERSION', '5.3.4');
define('COMPOSER_DIR_RELATIVE', 'composer');
define('COMPOSER_DIR_ABSOULTE', TL_ROOT . '/' . COMPOSER_DIR_RELATIVE);
/**
 * Initialize the composer runtime.
 */
\ContaoCommunityAlliance\Contao\Composer\Runtime::initialize();
/**
 * Default configuration
 */
$GLOBALS['TL_CONFIG']['composerAutoUpdateLibrary'] = true;
$GLOBALS['TL_CONFIG']['composerExecutionMode'] = 'inline';
$GLOBALS['TL_CONFIG']['composerPhpPath'] = '/usr/bin/env php -d memory_limit=1G -d max_execution_time=900';
$GLOBALS['TL_CONFIG']['composerRemoveRepositoryTables'] = false;
$GLOBALS['TL_CONFIG']['composerVerbosity'] = 'VERBOSITY_NORMAL';
/**
 * Add backend module
 */
$GLOBALS['BE_MOD']['system']['composer'] = array('callback' => 'ContaoCommunityAlliance\\Contao\\Composer\\ClientBackend', 'icon' => 'system/modules/!composer/assets/images/icon.png', 'stylesheet' => 'system/modules/!composer/assets/css/backend.css');
/**
 * Hooks
 */
 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 public function handle(\Input $input)
 {
     if (\Database::getInstance()->tableExists('tl_repository_installs')) {
         $oldPackageCount = \Database::getInstance()->execute('SELECT COUNT(*) AS count FROM tl_repository_installs')->count;
         $commercialPackages = \Database::getInstance()->execute('SELECT * FROM tl_repository_installs WHERE lickey!=\'\'')->fetchEach('extension');
         $commercialPackages = count($commercialPackages) ? implode(', ', $commercialPackages) : false;
     } else {
         $oldPackageCount = 0;
         $commercialPackages = '';
     }
     $smhEnabled = Runtime::isSafeModeHackEnabled();
     $allowUrlFopenEnabled = ini_get('allow_url_fopen');
     $pharSupportEnabled = false;
     $apcOpcodeCacheEnabled = ini_get('apc.enabled') && ini_get('apc.cache_by_default');
     try {
         if (class_exists('Phar', false)) {
             new \Phar(TL_ROOT . '/system/modules/!composer/config/test.phar');
             $pharSupportEnabled = true;
         }
     } catch (\Exception $e) {
     }
     $composerSupported = !$smhEnabled && $allowUrlFopenEnabled && $pharSupportEnabled;
     $gitAvailable = Runtime::testProcess('git --version');
     $hgAvailable = Runtime::testProcess('hg --version');
     $svnAvailable = Runtime::testProcess('svn --version');
     $mode = 'upgrade';
     $setup = 'production';
     if ($composerSupported && $input->post('FORM_SUBMIT') == 'tl_composer_migrate') {
         $target = 'contao/main.php?do=composer';
         $mode = $input->post('mode');
         $setup = $input->post('setup');
         // load config
         $json = new JsonFile(TL_ROOT . '/' . $this->configPathname);
         $config = $json->read();
         if ($input->post('skip')) {
             // mark migration skipped
             $config['extra']['contao']['migrated'] = 'skipped';
             Messages::addConfirmation($GLOBALS['TL_LANG']['composer_client']['migrationSkipped']);
         } else {
             if (\Database::getInstance()->tableExists('tl_repository_installs')) {
                 switch ($mode) {
                     case 'upgrade':
                         $this->removeER2Files();
                         $install = \Database::getInstance()->query('SELECT * FROM tl_repository_installs WHERE lickey=""');
                         while ($install->next()) {
                             // skip the composer package
                             if ($install->extension == 'composer') {
                                 continue;
                             }
                             $packageName = 'contao-legacy/' . $install->extension;
                             /*
                             $packageName = preg_replace(
                                 '{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}',
                                 '\\1\\3-\\2\\4',
                                 $packageName
                             );
                             */
                             $packageName = strtolower($packageName);
                             $oldVersion = $install->version;
                             $stability = $oldVersion % 10;
                             $oldVersion = (int) ($oldVersion / 10);
                             $oldVersion = (int) ($oldVersion / 1000);
                             $minor = $oldVersion % 1000;
                             $major = (int) ($oldVersion / 1000);
                             $version = sprintf('~%d.%d%s', $major, $minor, static::$versionNames[$stability]);
                             $config['require'][$packageName] = $version;
                         }
                         $target = 'contao/main.php?do=composer&update=packages';
                         break;
                     case 'clean':
                         $this->removeER2Files();
                         break;
                 }
             }
             switch ($setup) {
                 case 'production':
                     $config['minimum-stability'] = 'dev';
                     $config['prefer-stable'] = true;
                     $config['config']['preferred-install'] = 'dist';
                     break;
                 case 'development':
                     $config['minimum-stability'] = 'dev';
                     $config['prefer-stable'] = true;
                     $config['config']['preferred-install'] = 'source';
                     break;
             }
             // mark migration done
             $config['extra']['contao']['migrated'] = 'done';
             Messages::addConfirmation($GLOBALS['TL_LANG']['composer_client']['migrationDone']);
         }
         // write config
         $json->write($config);
         $this->redirect($target);
     }
     $template = new \BackendTemplate('be_composer_client_migrate');
     $template->composer = $this->composer;
     $template->smhEnabled = $smhEnabled;
     $template->allowUrlFopenEnabled = $allowUrlFopenEnabled;
     $template->pharSupportEnabled = $pharSupportEnabled;
     $template->composerSupported = $composerSupported;
     $template->apcOpcodeCacheEnabled = $apcOpcodeCacheEnabled;
     $template->oldPackageCount = $oldPackageCount;
     $template->commercialPackages = $commercialPackages;
     $template->gitAvailable = $gitAvailable;
     $template->hgAvailable = $hgAvailable;
     $template->svnAvailable = $svnAvailable;
     $template->mode = $mode;
     $template->setup = $setup;
     return $template->parse();
 }