public function execute()
 {
     global $IP;
     $lockLocation = "{$IP}/composer.lock";
     $jsonLocation = "{$IP}/composer.json";
     if (!file_exists($lockLocation)) {
         // Maybe they're using mediawiki/vendor?
         $lockLocation = "{$IP}/vendor/composer.lock";
         if (!file_exists($lockLocation)) {
             $this->error('Could not find composer.lock file. Have you run "composer install"?', 1);
         }
     }
     $lock = new ComposerLock($lockLocation);
     $json = new ComposerJson($jsonLocation);
     // Check all the dependencies to see if any are old
     $found = false;
     $installed = $lock->getInstalledDependencies();
     foreach ($json->getRequiredDependencies() as $name => $version) {
         if (isset($installed[$name])) {
             if ($installed[$name]['version'] !== $version) {
                 $this->output("{$name}: {$installed[$name]['version']} installed, {$version} required.\n");
                 $found = true;
             }
         } else {
             $this->output("{$name}: not installed, {$version} required.\n");
             $found = true;
         }
     }
     if ($found) {
         $this->error('Error: your composer.lock file is not up to date. ' . 'Run "composer update" to install newer dependencies', 1);
     } else {
         // We couldn't find any out-of-date dependencies, so assume everything is ok!
         $this->output("Your composer.lock file is up to date with current dependencies!\n");
     }
 }
 /**
  * Dependencies currently installed according to composer.lock
  *
  * @return array
  */
 public function getInstalledDependencies()
 {
     $deps = array();
     foreach ($this->contents['packages'] as $installed) {
         $deps[$installed['name']] = array('version' => ComposerJson::normalizeVersion($installed['version']), 'type' => $installed['type'], 'licenses' => isset($installed['license']) ? $installed['license'] : array(), 'authors' => isset($installed['authors']) ? $installed['authors'] : array(), 'description' => isset($installed['description']) ? $installed['description'] : '');
     }
     return $deps;
 }
예제 #3
0
 /**
  * Dependencies currently installed according to composer.lock
  *
  * @return array
  */
 public function getInstalledDependencies()
 {
     $deps = array();
     foreach ($this->contents['packages'] as $installed) {
         $deps[$installed['name']] = array('version' => ComposerJson::normalizeVersion($installed['version']), 'type' => $installed['type']);
     }
     return $deps;
 }
예제 #4
0
 /**
  * Dependencies currently installed according to installed.json
  *
  * @return array
  */
 public function getInstalledDependencies()
 {
     $deps = [];
     foreach ($this->contents as $installed) {
         $deps[$installed['name']] = ['version' => ComposerJson::normalizeVersion($installed['version']), 'type' => $installed['type'], 'licenses' => isset($installed['license']) ? $installed['license'] : [], 'authors' => isset($installed['authors']) ? $installed['authors'] : [], 'description' => isset($installed['description']) ? $installed['description'] : ''];
     }
     ksort($deps);
     return $deps;
 }
 public function execute()
 {
     global $IP;
     $lockLocation = "{$IP}/composer.lock";
     $jsonLocation = "{$IP}/composer.json";
     if (!file_exists($lockLocation)) {
         // Maybe they're using mediawiki/vendor?
         $lockLocation = "{$IP}/vendor/composer.lock";
         if (!file_exists($lockLocation)) {
             $this->error('Could not find composer.lock file. Have you run "composer install"?', 1);
         }
     }
     $lock = new ComposerLock($lockLocation);
     $json = new ComposerJson($jsonLocation);
     if ($lock->getHash() === $json->getHash()) {
         $this->output("Your composer.lock file is up to date with current dependencies!\n");
         return;
     }
     // Out of date, lets figure out which dependencies are old
     $found = false;
     $installed = $lock->getInstalledDependencies();
     foreach ($json->getRequiredDependencies() as $name => $version) {
         if (isset($installed[$name])) {
             if ($installed[$name]['version'] !== $version) {
                 $this->output("{$name}: {$installed[$name]['version']} installed, {$version} required.\n");
                 $found = true;
             }
         } else {
             $this->output("{$name}: not installed, {$version} required.\n");
             $found = true;
         }
     }
     if ($found) {
         $this->error('Error: your composer.lock file is not up to date, run "composer update" to install newer dependencies', 1);
     } else {
         // The hash is the entire composer.json file, so it can be updated without any of the dependencies changing
         // We couldn't find any out-of-date dependencies, so assume everything is ok!
         $this->output("Your composer.lock file is up to date with current dependencies!\n");
     }
 }
 /**
  * Scans a composer.json file provided by a Composer package.
  *
  * @param string $file
  * @param bool $relative
  *   If TRUE, the paths will be relative to $this->localDirectory.
  *
  * @throws \Exception
  */
 function composerJson($file, $relative = TRUE)
 {
     $relative && ($file = $this->localDirectory . $file);
     $json = ComposerJson::createFromFile($file);
     $json->writeToAdapter($this->master);
 }
 protected function needsComposerAutoloader($path)
 {
     $path .= '/composer.json';
     if (file_exists($path)) {
         // assume, that the composer.json file is in the root of the extension path
         $composerJson = new ComposerJson($path);
         // check, if there are some dependencies in the require section
         if ($composerJson->getRequiredDependencies()) {
             return true;
         }
     }
     return false;
 }
예제 #8
0
 /**
  * @dataProvider provideNormalizeVersion
  * @covers ComposerJson::normalizeVersion
  */
 public function testNormalizeVersion($input, $expected)
 {
     $this->assertEquals($expected, ComposerJson::normalizeVersion($input));
 }
 public function run($request)
 {
     increase_time_limit_to(3600);
     //Check temp module folder is empty
     $tempFolder = GitHubModule::Config()->get('absolute_temp_folder');
     $tempDirFiles = scandir($tempFolder);
     if (count($tempDirFiles) > 2) {
         die('<h2>' . $tempFolder . ' is not empty, please delete or move files </h2>');
     }
     //Get list of all modules from GitHub
     $gitUserName = $this->Config()->get('git_user_name');
     $modules = GitRepoFinder::get_all_repos();
     /*$modules = array (
                 'silverstripe-ecommerce_tax',
                 "silverstripe-gift_voucher",
                 "silverstripe-ecommerce_nutritional_products",
                 "silverstripe-ecommerce_countries",
                 "silverstripe-ecommerce_discount_coupon_countries",
                 "silverstripe-templateoverview",
                 "silverstripe-blog_shared_categorisation",
                 "silverstripe-webpack_requirements_backend",
                 "silverstripe-share_this_simple",
                 "silverstripe-phone_field",
                 "silverstripe-perfect_cms_images",
                 "silverstripe-email_address_database_field",
                 "silverstripe-ecommerce_stockists",
                 "silverstripe-ecommerce_dashboard",
                 "silverstripe-ecommerce_cloud_flare_geoip",
                 "silverstripe-comments_add_recaptcha",
                 "silverstripe-table_filter_sort",
                 "silverstripe-email_reminder",
                 "silverstripe-contact_list",
                 "silverstripe-cms_tricks_for_apps",
                 "silverstripe-cms_edit_link_field",
                 "silverstripe-frontendeditor",
                 "silverstripe-assets_sync_one_folder",
                 "silverstripe-payment_omnipay",
                 "silverstripe-sectionizer",
                 "silverstripe-ecommerce_vote",
                 "silverstripe-user_image_upload",
                 "silverstripe-ecommerce_reports",
                 "silverstripe-ecommerce_orderstep_feedback",
                 "silverstripe-silverstripe-ecommerce_orderstep_feedback",
                 "silverstripe-us_phone_number",
                 "silverstripe-title_dataobject",
                 "silverstripe-payment_stripe",
                 "silverstripe-silverstripe-assets_sync_one_folder",
     
                 );*/
     $updateComposerJson = $this->Config()->get('update_composer_json');
     $limitedModules = $this->Config()->get('modules_to_update');
     if ($limitedModules && count($limitedModules)) {
         $modules = array_intersect($modules, $limitedModules);
     }
     /*
      * Get files to add to modules
      * */
     $files = ClassInfo::subclassesFor('AddFileToModule');
     array_shift($files);
     $limitedFileClasses = $this->Config()->get('files_to_update');
     if ($limitedFileClasses && count($limitedFileClasses)) {
         $files = array_intersect($files, $limitedFileClasses);
     }
     /*
      * Get commands to run on modules
      * */
     $commands = ClassInfo::subclassesFor('RunCommandLineMethodOnModule');
     array_shift($commands);
     $limitedCommands = $this->Config()->get('commands_to_run');
     if ($limitedCommands && count($limitedCommands)) {
         $commands = array_intersect($commands, $limitedCommands);
     }
     foreach ($modules as $count => $module) {
         if (stripos($module, 'silverstripe-') === false) {
             $module = "silverstripe-" . $module;
         }
         echo "<h2>" . ($count + 1) . ". " . $module . "</h2>";
         $moduleObject = GitHubModule::get_or_create_github_module($module);
         $this->checkUpdateTag($moduleObject);
         // Check if all necessary files are perfect on GitHub repo already,
         // if so we can skip that module. But! ... if there are commands to run
         // over the files in the repo, then we need to clone the repo anyhow,
         // so skip the check
         if (count($commands) == 0 && !$updateComposerJson) {
             $moduleFilesOK = true;
             foreach ($files as $file) {
                 $fileObj = $file::create($moduleObject);
                 $checkFileName = $fileObj->getFileLocation();
                 $GitHubFileText = $moduleObject->getRawFileFromGithub($checkFileName);
                 if ($GitHubFileText) {
                     $fileCheck = $fileObj->compareWithText($GitHubFileText);
                     if (!$fileCheck) {
                         $moduleFilesOK = false;
                     }
                 } else {
                     $moduleFilesOK = false;
                 }
             }
             if ($moduleFilesOK) {
                 GeneralMethods::outputToScreen("<li> All files in {$module} OK, skipping to next module ... </li>");
                 continue;
             }
         }
         $repository = $moduleObject->checkOrSetGitCommsWrapper($forceNew = true);
         //$this->checkConfigYML($moduleObject);
         if ($updateComposerJson) {
             $composerJsonObj = new ComposerJson($moduleObject);
             $composerJsonObj->updateJsonData();
             $moduleObject->setDescription($composerJsonObj->getDescription());
         }
         foreach ($files as $file) {
             //run file update
             $obj = $file::create($moduleObject);
             $obj->run();
         }
         foreach ($commands as $command) {
             //run file update
             $obj = $command::create($moduleObject->Directory());
             $obj->run();
             //run command
         }
         //Update Repository description
         //$moduleObject->updateGitHubInfo(array());
         if (!$moduleObject->add()) {
             die("ERROR in add");
         }
         if (!$moduleObject->commit()) {
             die("ERROR in commit");
         }
         if (!$moduleObject->push()) {
             die("ERROR in push");
         }
         if (!$moduleObject->removeClone()) {
             die("ERROR in removeClone");
         }
         $moduleObject->addRepoToScrutinzer();
     }
     //to do ..
 }
 /**
  * {@inheritdoc}
  */
 function composerJson($file)
 {
     $json = ComposerJson::createFromFile($file);
     $json->writeToAdapter($this);
 }