Skip to content

Commit 68d6ade

Browse files
authored
Merge pull request #47 from flydev-fr/dev
Dev
2 parents 0ea42d3 + 19dd37e commit 68d6ade

File tree

7 files changed

+43
-157
lines changed

7 files changed

+43
-157
lines changed

Classes/ClientAmazonS3.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace ProcessWire;
4+
35
use Aws\S3\S3Client;
46

57
class AmazonS3Client
@@ -252,4 +254,4 @@ public function __construct($message = null, $code = 0, Exception $previous = nu
252254
DUP_Logs::log("AmazonS3: " . $message);
253255
parent::__construct($message, $code, $previous);
254256
}
255-
}
257+
}

Duplicator.js

Lines changed: 0 additions & 137 deletions
This file was deleted.

Duplicator.module

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace ProcessWire;
44

55
/*
6-
* Contributors:
6+
* Contributors and thanks to:
77
* - Szabesz (@szabeszg)
88
* - Stan Lindsey (@stanlindsey)
99
* - Adrian Jones (@adrianbj)
@@ -226,7 +226,6 @@ class Duplicator extends WireData implements Module, ConfigurableModule
226226

227227
$this->config->styles->add($this->config->urls->{$this->className} . "{$this->className}.css");
228228
$this->config->scripts->add($this->config->urls->{$this->className} . "Assets/lib/baffle.min.js");
229-
$this->config->scripts->add($this->config->urls->{$this->className} . "{$this->className}.js");
230229

231230
$this->defaultPath = wire('config')->paths->assets . self::DUP_DEFAULT_LOCAL_FOLDER;
232231
if (!is_dir($this->defaultPath) && empty($this->path)) {
@@ -607,9 +606,11 @@ class Duplicator extends WireData implements Module, ConfigurableModule
607606
return false;
608607
}
609608

609+
610+
610611
/*
611-
* call this function from a cron tool to launch the backup task
612-
*/
612+
* call this function from a cron tool to launch the backup task
613+
*/
613614
public function ___cronJob()
614615
{
615616
if (!$this->useLocalFolder && !$this->useDropbox && !$this->useGoogleDrive && !$this->useAmazonS3 && !$this->useFTP) {
@@ -711,7 +712,7 @@ class Duplicator extends WireData implements Module, ConfigurableModule
711712
throw new WireException("AmazonS3 SDK not installed.");
712713
}
713714

714-
$amazonaws = new \AmazonS3Client();
715+
$amazonaws = new AmazonS3Client();
715716
$amazonaws->setAccessKey($this->awsAccessKey);
716717
$amazonaws->setSecretKey($this->awsSecretKey);
717718
$amazonaws->setRegion($this->awsRegion);
@@ -731,7 +732,7 @@ class Duplicator extends WireData implements Module, ConfigurableModule
731732
$amazonaws->upload($package['zipfile'], $packageName, $this->awsSubDir);
732733
//if($url === null) throw new AmazonS3ClientException("AmazonS3: An error occured while uploading package <{$packageName}>");
733734
$amazonaws->deleteOldBackups($this->maxPackages, $this->deadline);
734-
} catch (\AmazonS3ClientException $ex) {
735+
} catch (AmazonS3ClientException $ex) {
735736
DUP_Logs::log("[AmazonS3] error: " . $ex->getMessage(), 'warning');
736737
}
737738
}
@@ -853,7 +854,13 @@ class Duplicator extends WireData implements Module, ConfigurableModule
853854

854855
$dirsToProcess = ['/']; // Start at root
855856

856-
set_time_limit(300); // Try to allow longer execution time
857+
if ($this->cronMode !== 'none') {
858+
DUP_Logs::log("- running ZipData2() with cronMode = {$this->cronMode}");
859+
DUP_Logs::log("- trying to allow longer execution time");
860+
set_time_limit(300); // Try to allow longer execution time
861+
DUP_Logs::log("- php time limit => " . ini_get('max_execution_time') . " sec");
862+
}
863+
857864
while ($thisDir = array_shift($dirsToProcess)) { // Process first entry in array
858865
$fullPath = $rootDirectory . $thisDir;
859866

@@ -935,7 +942,12 @@ class Duplicator extends WireData implements Module, ConfigurableModule
935942

936943
$zipLog->verbose("OPENED ZIP: {$zipfile}");
937944
$fragmentBytes = 0;
938-
set_time_limit(300);
945+
if ($this->cronMode !== 'none') {
946+
DUP_Logs::log("- running ZipData2() with cronMode = {$this->cronMode}");
947+
DUP_Logs::log("- trying to allow longer execution time");
948+
set_time_limit(300); // Try to allow longer execution time
949+
DUP_Logs::log("- php time limit => " . ini_get('max_execution_time') . " sec");
950+
}
939951
}
940952
} else {
941953
$ret['errors'][] = $filePath;
@@ -1230,6 +1242,7 @@ class Duplicator extends WireData implements Module, ConfigurableModule
12301242
$out .= " <a class='github-button' href='https://github.com/flydev-fr/Duplicator' data-show-count='false' aria-label='Documentation' data-size='large'>Doc</a>";
12311243
$out .= " </div>";
12321244
$out .= "</div>";
1245+
$out .= "<script>baffle('.dup-glitch', {characters: '█▓█ ▒░1▒░3█░▒▓3 █▒▒7▓▒▓ █ ░█▒ ▒▓░: █)░▒ ▓░', speed: 110}).reveal(11500);</script>";
12331246

12341247
$fs = $modules->get("InputfieldFieldset");
12351248
$fs->label = " ";
@@ -1405,6 +1418,7 @@ class Duplicator extends WireData implements Module, ConfigurableModule
14051418
if ($data['cycle'] == 'logoutTrigger') {
14061419
$field->notes = __("The cronjob to backup your database executes only if current user has db-backup permission.");
14071420
}
1421+
$field->showIf = "cronMode='LazyCron'";
14081422

14091423
$field->addOptions(array(
14101424
0 => __('Trigger disabled'),
@@ -1516,14 +1530,14 @@ class Duplicator extends WireData implements Module, ConfigurableModule
15161530
$f->description = __("Shell script used to backup database in Native Mode.");
15171531
$f->notes = __("This script is used to backup database in Native Mode. You can edit this script to fit your needs.");
15181532
// load from stub
1519-
$f->value = $data['shellScript'] ? $data['shellScript'] : '';
15201533
$f->icon = 'terminal';
15211534
$f->columnWidth = 100;
15221535
$f->rows = 18;
15231536
$f->collapsed = $data['backup_mode'] == self::DUP_MODE_NATIVE ? ($data['shellScript'] == '' ? true : false) : false;
15241537
$f->showIf = "backup_mode=".self::DUP_MODE_NATIVE;
15251538
$stub = DUP_Util::getStub();
1526-
$f->placeholder = $stub ? file_get_contents($stub) : 'Paste or write your custom dump shell script here...';
1539+
$f->placeholder = 'Paste or write your custom dump shell script here...';
1540+
$f->value = $data['shellScript'] ? $data['shellScript'] : ($stub ? file_get_contents($stub) : '');
15271541
$fs->append($f);
15281542

15291543
$field = $modules->get('InputfieldCheckbox');
@@ -1543,6 +1557,9 @@ class Duplicator extends WireData implements Module, ConfigurableModule
15431557

15441558
$fields->append($fs);
15451559

1560+
/**
1561+
* Cloud Providers Settings
1562+
*/
15461563
$fs = $modules->get("InputfieldFieldset");
15471564
$fs->label = "Save package to";
15481565
$fs->icon = 'cloud';
@@ -1738,7 +1755,7 @@ class Duplicator extends WireData implements Module, ConfigurableModule
17381755
$fs->append($fsgd);
17391756

17401757
// AMAZON
1741-
if (!class_exists('AmazonS3Client')) {
1758+
if (!class_exists('\Aws\S3\S3Client')) {
17421759
$skip = true;
17431760
}
17441761
$description = ($skip == false) ? $disabled = '' : __("The required SDK is not installed. You can download it [here](https://github.com/flydev-fr/duplicator-amazon-s3) or install it with [Composer](https://getcomposer.org/doc/00-intro.md). Run **composer require aws/aws-sdk-php**");
@@ -1843,4 +1860,4 @@ class Duplicator extends WireData implements Module, ConfigurableModule
18431860

18441861
$event->return = str_replace("</head>", "\r\n$github</head>", $event->return);
18451862
}
1846-
}
1863+
}

ProcessDuplicator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ $(document).ready(function () {
7979
});
8080

8181
function backupNow() {
82-
if ($job == true) {
82+
if ($job == true) {
8383
return;
8484
}
8585

ProcessDuplicator.module

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ class ProcessDuplicator extends Process
453453
// AmazonS3
454454
if ($this->dupmod->useAmazonS3 == 1) {
455455
try {
456-
$amazonaws = new \AmazonS3Client();
456+
$amazonaws = new AmazonS3Client();
457457
$amazonaws->setAccessKey($this->dupmod->awsAccessKey);
458458
$amazonaws->setSecretKey($this->dupmod->awsSecretKey);
459459
$amazonaws->setRegion($this->dupmod->awsRegion);
@@ -464,7 +464,10 @@ class ProcessDuplicator extends Process
464464
foreach ($files as $file) {
465465
if (strrpos($file['Key'], $extension) == false) continue;
466466
$originalFilename = $file['Key'];
467-
$parts = explode('-', $file['Key']);
467+
if ($this->dupmod->awsSubDir !== '' && strpos($originalFilename, $this->dupmod->awsSubDir) === 0) {
468+
$originalFilename = substr($originalFilename, strlen($this->dupmod->awsSubDir . '/'));
469+
}
470+
$parts = explode('-', $originalFilename);
468471
array_pop($parts);
469472
$tsstr = implode('-', $parts);
470473
$ts = date_create_from_format(Duplicator::DUP_TIMESTAMP_FORMAT, $tsstr);
@@ -473,9 +476,8 @@ class ProcessDuplicator extends Process
473476
$href1 = '<a href="?action=packages&installer=' . $originalFilename . '" class="btnlink"><i class="fa fa-bolt"></i> Installer</a>';
474477
$href2 = '<a href="?action=packages&file=' . $originalFilename . '&service=amazon" class="btnlink" title="Synchronize the package from the Cloud to your Server."><i class="fa fa-cloud-download"></i> Sync</a>';
475478
$href3 = '<a href="?action=delete&file=' . $file['Key'] . '&service=amazon" class="trashTrigger" data-action="' . $dataAction . '"><i class="fa fa-trash"></i></a>';
476-
477479
$data = array(
478-
'time' => $ts->getTimestamp(),
480+
'time' => $ts ? $ts->getTimestamp() : 0,
479481
"<img src='{$this->config->urls->siteModules}{$this->dupmod->className}/Assets/amazon-64.png'> <span class='package-name'>" . $originalFilename . "</span>",
480482
$createdOn,
481483
DUP_Util::human_filesize($file['Size']),
@@ -485,7 +487,7 @@ class ProcessDuplicator extends Process
485487
array_push($rows, $data);
486488
}
487489
}
488-
} catch (\AmazonS3ClientException $ex) {
490+
} catch (AmazonS3ClientException $ex) {
489491
DUP_Logs::log("AmazonS3 error: " . $ex->getMessage(), 'error');
490492
}
491493
}

scripts/mysqldump.unix.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# (1) Set up all the mysqldump variables
44
FILE=%%FILE%%
55
DBSERVER=%%SERVER%%
6+
PORT=%%PORT%%
67
DATABASE=%%DATABASE%%
78
USER=%%USER%%
89
PASS=%%PASS%%
@@ -21,6 +22,6 @@ OUTPUT="${CACHEPATH}${FILE}"
2122
# (3) Do the mysql database backup (dump)
2223
# - to log errors of the dump process to a file, add --log-error=mysqldump_dup_error.log
2324
# (a) Use this command for a remote database. Add other options if need be.
24-
# mysqldump --opt --protocol=TCP --user=${USER} --password=${PASS} --host=${DBSERVER} --port=${PORT} ${DATABASE} ${DATABASE} > ${OUTPUT}
25+
# mysqldump --opt --protocol=TCP --user=${USER} --password=${PASS} --host=${DBSERVER} --port=${PORT} ${DATABASE} > ${OUTPUT}
2526
# (b) Use this command for a database server on localhost. Add other options if need be.
2627
mysqldump --routines --triggers --single-transaction --user=${USER} --password=${PASS} --databases ${DATABASE} > ${OUTPUT}

scripts/mysqldump.windows.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set USER=%%USER%%
77
set PASS=%%PASS%%
88
set FILE=%%FILE%%
99
set CACHEPATH=%%CACHEPATH%%
10+
REM set PORT=%%PORT%%
1011

1112
REM Fix trailing slash in cache path
1213
set lastchar=%CACHEPATH%:~-1%

0 commit comments

Comments
 (0)