Skip to content

Commit

Permalink
Merge pull request #26 from FriendsOfREDAXO/skerbis-patch-1
Browse files Browse the repository at this point in the history
tmp in cache
  • Loading branch information
skerbis authored Sep 15, 2024
2 parents b7bf832 + 17f3d66 commit 7297e92
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
2 changes: 0 additions & 2 deletions install.php

This file was deleted.

11 changes: 7 additions & 4 deletions lib/zip_upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
* @var rex_addon
*/


class zip_upload extends zip_install
{
public static function validateAndExtractUpload()
{
if (!empty($_FILES['file']))
{
$tmp_path = rex_path::addon('zip_install');
$tmp_path = rex_addon::get('zip_install')->getCachePath('tmp_uploads');

// Ensure the temporary path exists
if (!file_exists($tmp_path)) {
rex_dir::create($tmp_path);
}

$parentIsMissing = false;

$upload = Upload::factory('tmp', $tmp_path);
Expand All @@ -34,8 +39,6 @@ public static function validateAndExtractUpload()
{
echo rex_view::warning(rex_i18n::rawMsg('zip_install_upload_failed'));
}

}
}

}
22 changes: 10 additions & 12 deletions lib/zip_url.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* zip_install Addon.
*
Expand All @@ -8,7 +7,6 @@
*
* @var rex_addon
*/

class zip_url extends zip_install
{
protected static function downloadFile($url, $destination)
Expand All @@ -20,11 +18,9 @@ protected static function downloadFile($url, $destination)
$redircount = 0;
while ($response->isRedirection() && $redircount < 3) {
$location = $response->getHeader('Location');

if (empty($location)) {
return false;
}

# add host if needed
if (strpos($location, '//') === false) {
$parsed = parse_url($url);
Expand All @@ -34,16 +30,13 @@ protected static function downloadFile($url, $destination)
}
$location = $host . $location;
}

$socket = rex_socket::factoryURL($location);
$response = $socket->doGet();
$redircount++;
}

if (!$response->isOk()) {
return false;
}

// write to file
if ($response->writeBodyTo($destination)) {
return true;
Expand All @@ -56,21 +49,27 @@ protected static function downloadFile($url, $destination)
public static function validateAndExtractUpload()
{
$fileUrl = rex_post('file_url');

if (!empty($fileUrl)) {
$tmp_file = rex_path::addon('zip_install', 'tmp/._tmp.zip');
$tmp_path = rex_addon::get('zip_install')->getCachePath('tmp_uploads');

// Ensure the temporary path exists
if (!file_exists($tmp_path)) {
rex_dir::create($tmp_path);
}

$tmp_file = $tmp_path . '/._tmp.zip';

$isGithubRepo = preg_match("/^https:\/\/github\.com\/[\w-]+\/[\w-]+$/", $fileUrl);
$isGithubBranch = preg_match("/^https:\/\/github\.com\/[\w-]+\/[\w-]+\/tree\/[\w\.-]+$/", $fileUrl);

if ($isGithubRepo) {
$mainBranchUrl = $fileUrl . '/archive/main.zip';
$masterBranchUrl = $fileUrl . '/archive/master.zip';

// Versuche zuerst den 'main'-Branch
if (self::downloadFile($mainBranchUrl, $tmp_file) && file_exists($tmp_file)) {
self::installZip($tmp_file);
return;
}

// Versuche dann den 'master'-Branch
if (self::downloadFile($masterBranchUrl, $tmp_file) && file_exists($tmp_file)) {
self::installZip($tmp_file);
Expand All @@ -90,7 +89,6 @@ public static function validateAndExtractUpload()
return;
}
}

echo rex_view::error(rex_i18n::rawMsg('zip_install_url_file_not_loaded'));
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package: zip_install
version: '1.4.0'
version: '1.5.0'
author: Friends Of REDAXO
supportpage: github.com/FriendsOfREDAXO/zip_install

Expand Down
1 change: 0 additions & 1 deletion tmp/.redaxo

This file was deleted.

17 changes: 12 additions & 5 deletions update.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<?php
$tmpPath = rex_path::addon('zip_install','tmp');
if(!rex_dir::isWritable($tmpPath)) {
if(is_dir($tmpPath)) {
@chmod($tmpPath, 0755);
$addon = rex_addon::get('zip_install');

if (rex_version::compare($addon->getVersion(), '1.5', '<')) {
$tmpPath = rex_path::addon('zip_install', 'tmp');

if (is_dir($tmpPath)) {
// Try to delete the directory
if (!rex_dir::delete($tmpPath)) {
// If deletion fails, log a warning
rex_logger::logWarning('The temporary directory ' . $tmpPath . ' could not be deleted.');
} else {
@mkdir($tmpPath, 0755);
rex_logger::logInfo('The temporary directory ' . $tmpPath . ' has been successfully deleted.');
}
}
}

0 comments on commit 7297e92

Please sign in to comment.