Skip to content

Commit

Permalink
Updated installer for testing extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
markseuffert committed Dec 4, 2023
1 parent c4a5ea5 commit df164f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
26 changes: 23 additions & 3 deletions system/extensions/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Install extension, https://github.com/annaesvensson/yellow-install

class YellowInstall {
const VERSION = "0.8.92";
const VERSION = "0.8.93";
const PRIORITY = "1";
public $yellow; // access to API

Expand Down Expand Up @@ -91,7 +91,7 @@ public function processCommandInstall($command, $text) {
echo "ERROR installing files: ".$this->yellow->page->errorMessage."\n";
echo "The installation has not been completed. Please run command again.\n";
} else {
$extensions = count($this->yellow->extension->data);
$extensions = $this->getExtensionsCount();
echo "Yellow $command: $extensions extension".($extensions!=1 ? "s" : "").", 0 errors\n";
}
} else {
Expand Down Expand Up @@ -398,12 +398,15 @@ public function downloadExtensionsLatest() {
$path = $this->yellow->system->get("coreExtensionDirectory");
$fileData = $this->yellow->toolbox->readFile($path.$this->yellow->system->get("updateLatestFile"));
$settings = $this->yellow->toolbox->getTextSettings($fileData, "extension");
$extensionsNow = 0;
$extensionsEstimated = count($settings) - substr_count(strtoloweru($fileData), "tag: language");
$curlHandle = curl_init();
foreach ($settings as $key=>$value) {
$fileName = $path."install-".$this->yellow->lookup->normaliseName($key, true, false, true).".bin";
if (is_file($fileName)) continue;
$url = $value->get("downloadUrl");
if (preg_match("/language/i", $value->get("tag"))) continue;
echo "\rDownloading latest extensions ".$this->getProgressPercent(++$extensionsNow, $extensionsEstimated, 5, 95)."%... ";
$url = $value->get("downloadUrl");
curl_setopt($curlHandle, CURLOPT_URL, $this->yellow->extension->get("update")->getExtensionDownloadUrl($url));
curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; YellowInstall/".YellowInstall::VERSION).")";
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
Expand Down Expand Up @@ -432,6 +435,7 @@ public function downloadExtensionsLatest() {
if ($statusCode!=200) break;
}
curl_close($curlHandle);
echo "\rDownloading latest extensions 100%... done\n";
}
return $statusCode;
}
Expand Down Expand Up @@ -469,6 +473,14 @@ public function getExtensionsRequired($fileData, $option) {
return $extensions;
}

// Return extensions installed
public function getExtensionsCount() {
$fileNameCurrent = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("updateCurrentFile");
$fileData = $this->yellow->toolbox->readFile($fileNameCurrent);
$settings = $this->yellow->toolbox->getTextSettings($fileData, "extension");
return count($settings);
}

// Return system languages
public function getSystemLanguages($languagesDefault) {
$languages = array();
Expand Down Expand Up @@ -527,6 +539,14 @@ public function getRawDataInstall() {
return $rawData;
}

// Return progress in percent
public function getProgressPercent($now, $total, $increments, $max) {
$max = intval($max/$increments) * $increments;
$percent = intval(($max/$total) * $now);
if ($increments>1) $percent = intval($percent/$increments) * $increments;
return min($max, $percent);
}

// Check if running built-in web server
public function isServerBuiltin() {
list($name) = $this->yellow->toolbox->detectServerInformation();
Expand Down
4 changes: 2 additions & 2 deletions system/extensions/update-current.ini
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ media/images/photo.jpg: photo.jpg, create, optional
media/thumbnails/photo-100x40.jpg: photo-100x40.jpg, create, optional

Extension: Install
Version: 0.8.92
Version: 0.8.93
Description: Install a brand new website.
DocumentationUrl: https://github.com/annaesvensson/yellow-install
DownloadUrl: https://github.com/annaesvensson/yellow-install/archive/refs/heads/main.zip
Published: 2023-12-03 03:23:42
Published: 2023-12-04 20:53:04
Developer: Anna Svensson
Status: unlisted
system/extensions/install.php: install.php, create
Expand Down

0 comments on commit df164f1

Please sign in to comment.