Skip to content

Commit

Permalink
Change the logic for composer project json url and use latest if it w…
Browse files Browse the repository at this point in the history
…as listed in the update rule config #16
  • Loading branch information
Natshah committed Jul 10, 2019
1 parent 920d949 commit 77c2be7
Show file tree
Hide file tree
Showing 9 changed files with 611 additions and 363 deletions.
12 changes: 8 additions & 4 deletions config/update-config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"profile": "varbase",
"package": "vardot/varbase",
"8.4.*": {
"8.4.*": {
"from": "8.4.*",
"to": "8.4.28"
},
Expand Down Expand Up @@ -29,6 +29,10 @@
},
"8.5.*": {
"from": "8.5.*",
"to": "8.5.5"
},
"8.5.5": {
"from": "8.5.5",
"to": "8.6.3",
"packages": {
"crucial": {
Expand Down Expand Up @@ -62,7 +66,7 @@
},
"8.7.*": {
"from": "8.7.*",
"to": "8.7.*"
},
"composer-project-json-url": "https://raw.githubusercontent.com/Vardot/varbase-project/8.7.x/composer.json"
"to": "8.7.*",
"composer-project-json-url": "latest"
}
}
4 changes: 3 additions & 1 deletion scripts/update/update-varbase.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/bash

# Update Varbase

BASEDIR=$(pwd);

echo "$(tput setaf 2)Checking composer version and updating if needed:$(tput sgr 0)";
composer self-update;
echo "$(tput setaf 2)Checking varbase-updater version and updating if needed:$(tput sgr 0)";
composer update vardot/varbase-updater;

#running the updater;
# Running the updater.
bash ${BASEDIR}/vendor/vardot/varbase-updater/scripts/update/varbase-updater.sh
249 changes: 135 additions & 114 deletions scripts/update/update.php
Original file line number Diff line number Diff line change
@@ -1,136 +1,157 @@
<?php

function get_file($url, $local_path, $newfilename)
{
$err_msg = '';
echo "Downloading $url";
echo "\n";
$out = fopen($local_path.$newfilename,"wrxb");
if ($out == FALSE){
print "File not opened.<br>";
exit;
}
function get_file($url, $local_path, $newfilename) {
$err_msg = '';
echo "Downloading $url";
echo "\n";
$out = fopen($local_path.$newfilename, "wrxb");
if ($out == FALSE){
print "File not opened.<br>";
exit;
}

$ch = curl_init();
$ch = curl_init();

curl_setopt($ch, CURLOPT_FILE, $out);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FILE, $out);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);

curl_exec($ch);
curl_exec($ch);

curl_close($ch);
//fclose($handle);
curl_close($ch);
//fclose($handle);

}//end function
} //end function

echo "Starting varbase-project updater!\n";
echo "Starting varbase-project updater!\n";

$path = getcwd()."/composer.json";
if(!file_exists($path)){
echo "\n";
echo "Please run this command from your varbase-project root directory";
echo "\n";
exit;
}
$string = file_get_contents(getcwd()."/composer.json");
$json=json_decode($string,true);

if(isset($json["name"]) && $json["name"] != "vardot/varbase-project") {
echo "\n";
echo "Please run this command from your varbase-project root directory";
echo "\n";
exit;
}
$path = getcwd()."/composer.json";
if (!file_exists($path)) {
echo "\n";
echo "Please run this command from your varbase-project root directory";
echo "\n";
exit;
}
$string = file_get_contents(getcwd()."/composer.json");
$json=json_decode($string,true);

if(!isset($json["name"])){
echo "\n";
echo "Please run this command from your varbase-project root directory";
echo "\n";
exit;
}
if (isset($json["name"]) && $json["name"] != "vardot/varbase-project") {
echo "\n";
echo "Please run this command from your varbase-project root directory";
echo "\n";
exit;
}

if(!isset($json["autoload"])){
$json["autoload"] = [
"psr-4" => [
if (!isset($json["name"])) {
echo "\n";
echo "Please run this command from your varbase-project root directory";
echo "\n";
exit;
}

if (!isset($json["autoload"])) {
$json["autoload"] = [
"psr-4" => [
"Varbase\\composer\\" => "scripts/composer"
]
];
}
else if(isset($json["autoload"]["psr-4"])) {
$json["autoload"]["psr-4"]["Varbase\\composer\\"] = "scripts/composer";
}
else {
$json["autoload"]["psr-4"] = [
"Varbase\\composer\\" => "scripts/composer"
]
];
}else if(isset($json["autoload"]["psr-4"])){
$json["autoload"]["psr-4"]["Varbase\\composer\\"] = "scripts/composer";
}else{
$json["autoload"]["psr-4"] = [
"Varbase\\composer\\" => "scripts/composer"
];
}

if(!isset($json["scripts"])){
$json["scripts"] = [
"varbase-composer-generate" => [
];
}

if (!isset($json["scripts"])) {
$json["scripts"] = [
"varbase-composer-generate" => [
"Varbase\\composer\\VarbaseUpdate::generate"
]
];
}
else if(isset($json["scripts"])) {
$json["scripts"]["varbase-composer-generate"]= [
"Varbase\\composer\\VarbaseUpdate::generate"
]
];
}else if(isset($json["scripts"])){
$json["scripts"]["varbase-composer-generate"]= [
"Varbase\\composer\\VarbaseUpdate::generate"
];
}
$drupalPath = "docroot";
if (file_exists(getcwd().'/web')) {
$drupalPath = "web";
}

echo "Drupal root set to " . $drupalPath . " if your Drupal root is different than this, please change install-path inside your composer.json under the 'extra' section.\n";

if(!isset($json["extra"])){
$json["extra"] = [
"install-path" => $drupalPath
];
}else{
$json["extra"]["install-path"] = $drupalPath;
}

$jsondata = json_encode($json, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);


if (!file_exists(getcwd().'/scripts/composer')) {
];
}

$drupalPath = "docroot";
if (file_exists(getcwd().'/web')) {
$drupalPath = "web";
}

echo "Drupal root set to " . $drupalPath . " if your Drupal root is different than this, please change install-path inside your composer.json under the 'extra' section.\n";

if (!isset($json["extra"])) {
$json["extra"] = [
"install-path" => $drupalPath
];
}
else {
$json["extra"]["install-path"] = $drupalPath;
}

$jsondata = json_encode($json, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);


if (!file_exists(getcwd().'/scripts/composer')) {
mkdir(getcwd().'/scripts/composer', 0777, true);
}
}

if (!file_exists(getcwd().'/scripts/update')) {
if (!file_exists(getcwd().'/scripts/update')) {
mkdir(getcwd().'/scripts/update', 0777, true);
}
}

if (!file_exists(getcwd().'/drush')) {
if (!file_exists(getcwd().'/drush')) {
mkdir(getcwd().'/drush', 0777, true);
}
}

if (!file_exists(getcwd().'/bin')) {
if (!file_exists(getcwd().'/bin')) {
mkdir(getcwd().'/bin', 0777, true);
}
$base_path = "https://raw.githubusercontent.com/Vardot/varbase-updater/master/";
get_file($base_path . "scripts/composer/VarbaseUpdate.php", getcwd().'/scripts/composer/', 'VarbaseUpdate.php');
get_file($base_path . "scripts/update/update-varbase.sh", getcwd().'/scripts/update/', 'update-varbase.sh');
get_file($base_path . "scripts/update/version-check.php", getcwd().'/scripts/update/', 'version-check.php');
get_file($base_path . "scripts/update/update-config.json", getcwd().'/scripts/update/', 'update-config.json');
//only download them if they don't exist
if (!file_exists(getcwd().'/drush/policy.drush.inc')) {
}

// Get the latest release for Varbase Updater.
$varbaseUpdaterLatestRelease = [];
$varbaseUpdaterJsonUrl = "https://api.github.com/repos/vardot/varbase-updater/releases/latest";
$varbaseUpdaterFilename = uniqid(sys_get_temp_dir().'/') . ".json";
get_file($varbaseUpdaterJsonUrl, $varbaseUpdaterFilename, $varbaseUpdaterFilename);

if (file_exists($varbaseUpdaterFilename)) {
$varbaseUpdaterLatestRelease = JsonFile::parseJson(file_get_contents($varbaseUpdaterFilename), $varbaseUpdaterFilename);
}

// Varbase Updater Latest release tag name.
$tagName = $varbaseUpdaterLatestRelease['tag_name'];

$base_path = "https://raw.githubusercontent.com/vardot/varbase-updater/" . $tagName . "/";
get_file($base_path . "scripts/composer/VarbaseUpdate.php", getcwd().'/scripts/composer/', 'VarbaseUpdate.php');
get_file($base_path . "scripts/update/update-varbase.sh", getcwd().'/scripts/update/', 'update-varbase.sh');
get_file($base_path . "scripts/update/version-check.php", getcwd().'/scripts/update/', 'version-check.php');
get_file($base_path . "scripts/update/update-config.json", getcwd().'/scripts/update/', 'update-config.json');

// Only download them if they don't exist.
if (!file_exists(getcwd().'/drush/policy.drush.inc')) {
get_file($base_path . "drush/policy.drush.inc", getcwd().'/drush/', 'policy.drush.inc');
}
if (!file_exists(getcwd().'/drush/README.md')) {
}

if (!file_exists(getcwd().'/drush/README.md')) {
get_file($base_path . "drush/README.md", getcwd().'/drush/', 'README.md');
}

chmod(getcwd().'/scripts/update/update-varbase.sh', 0755);
chmod(getcwd().'/scripts/update/version-check.php', 0755);
chmod(getcwd().'/scripts/composer/VarbaseUpdate.php', 0755);

if(file_put_contents($path, $jsondata)) {
echo "varbase-project successfully updated.\n";
echo "Now you can run ./scripts/update/update-varbase.sh to update Varbase to the latest version.\n";
echo "Enjoy!\n";
}else{
echo "Error while updating varbase-project.\n";
echo ":(\n";
}
}

chmod(getcwd().'/scripts/update/update-varbase.sh', 0755);
chmod(getcwd().'/scripts/update/version-check.php', 0755);
chmod(getcwd().'/scripts/composer/VarbaseUpdate.php', 0755);

if (file_put_contents($path, $jsondata)) {
echo "varbase-project successfully updated.\n";
echo "Now you can run ./scripts/update/update-varbase.sh to update Varbase to the latest version.\n";
echo "Enjoy!\n";
}
else {
echo "Error while updating varbase-project.\n";
echo ":(\n";
}
5 changes: 4 additions & 1 deletion scripts/update/varbase-updater.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

# Varbase Updater

function clear_stdin(){
while read -e -t 1; do : ; done
while read -e -t 1; do : ; done
}

BASEDIR=$(pwd);
Expand Down
26 changes: 17 additions & 9 deletions src/Commands/CommandsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@

use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;

class CommandsProvider implements CommandProviderCapability
{
public function getCommands()
{
return array(
new RefactorComposerCommand,
new VersionCheckComposerCommand
);
}
/**
* Commands provider.
*/
class CommandsProvider implements CommandProviderCapability {

/**
* Get Commands.
*
* @return type
*/
public function getCommands() {
return array (
new RefactorComposerCommand,
new VersionCheckComposerCommand
);
}

}
Loading

0 comments on commit 77c2be7

Please sign in to comment.