Skip to content

Commit

Permalink
Update market.class.php
Browse files Browse the repository at this point in the history
  • Loading branch information
sergejey committed May 23, 2023
1 parent 00f17ab commit b08c1ac
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions modules/market/market.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,30 +674,40 @@ function updateAll($can_be_updated, $frame = 0)

if (is_array($can_be_updated)) {
foreach ($can_be_updated as $k => $v) {

//$this->getLatest($out, $v['URL'], $v['NAME'], $v['VERSION']);
$name = $v['NAME'];
$version = $v['VERSION'];
$url = $v['URL'];



$filename = ROOT . 'cms/saverestore/' . $name . '.tgz';
if (file_exists($filename)) {
unlink($filename);
}
$filename = ROOT . 'cms/saverestore/' . $name . '.tar';
if (file_exists($filename)) {
unlink($filename);
$filename2 = ROOT . 'cms/saverestore/' . $name . '.tar';
if (file_exists($filename2)) {
unlink($filename2);
}

$f = fopen($filename, 'wb');
if ($f == FALSE) {
$this->redirect("?err_msg=" . urlencode("Cannot open " . $filename . " for writing"));
}

if (!isset($url) || !$url) {
if ($frame) {
$this->echonow("No download URL available for $name ($version).<br/>");
}
continue;
}

if ($frame) {
$this->echonow("Downloading '$url' ... ");
}

DebMes("Downloading plugin $name ($version) from $url");
DebMes("Downloading plugin $name ($version) from $url",'market');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 600);
Expand All @@ -709,20 +719,19 @@ function updateAll($can_be_updated, $frame = 0)
curl_close($ch);
@fclose($f);

if (file_exists($filename)) {
if (file_exists($filename) && filesize($filename)>0) {

if ($frame) {
$this->echonow("OK<br/>", 'green');
}


$file = basename($filename);
DebMes("Installing/updating plugin $name ($version)");
DebMes("Installing/updating plugin $name ($version)",'market');

chdir(ROOT . 'cms/saverestore/temp');

if ($frame) {
$this->echonow("Unpacking '$file' ..");
$this->echonow("Unpacking '$file' ...");
}

if (IsWindowsOS()) {
Expand All @@ -734,8 +743,8 @@ function updateAll($can_be_updated, $frame = 0)
}

if (!$result) {
$this->echonow("Unpack failed!", 'red');
return false;
$this->echonow("Unpack failed!<br/>", 'red');
continue;
}

$x = 0;
Expand All @@ -760,13 +769,13 @@ function updateAll($can_be_updated, $frame = 0)

chdir('../../');

DebMes("Latest folder: $latest_dir");
DebMes("Latest folder: $latest_dir",'market');

if ($latest_dir == '') {
if ($frame) {
$this->echonow("ERROR<br/>", 'red');
}
DebMes("Error extracting $file");
DebMes("Error extracting $file",'market');
continue;
}

Expand Down Expand Up @@ -799,6 +808,10 @@ function updateAll($can_be_updated, $frame = 0)
}
$this->checkIfCycleRestartRequired($name);

} else {
if ($frame) {
$this->echonow("Download failed.<br/>",'red');
}
}
}
}
Expand Down Expand Up @@ -1139,7 +1152,7 @@ function upload(&$out, $frame = 0)
}


DebMes("Installing/updating plugin $name ($version)");
DebMes("Installing/updating plugin $name ($version)",'market');

$rec = SQLSelectOne("SELECT * FROM plugins WHERE MODULE_NAME LIKE '" . DBSafe($name) . "'");
$rec['MODULE_NAME'] = $name;
Expand Down Expand Up @@ -1362,7 +1375,7 @@ function copyFiles($source, $destination, $over = 0, $patterns = 0)

function echonow($msg, $color = '')
{
DebMes(strip_tags($msg), 'auto_update');
DebMes(strip_tags($msg), 'market');
if ($color) {
echo '<font color="' . $color . '">';
}
Expand Down

0 comments on commit b08c1ac

Please sign in to comment.