forked from PrestaShop/autoupgrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDownload.php
97 lines (90 loc) · 5.31 KB
/
Download.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade;
use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask;
use PrestaShop\Module\AutoUpgrade\UpgradeContainer;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\FilesystemAdapter;
/**
* Download PrestaShop archive according to the chosen channel.
*/
class Download extends AbstractTask
{
public function run()
{
if (!\ConfigurationTest::test_fopen() && !\ConfigurationTest::test_curl()) {
$this->logger->error($this->translator->trans('You need allow_url_fopen or cURL enabled for automatic download to work. You can also manually upload it in filepath %s.', [$this->container->getFilePath()], 'Modules.Autoupgrade.Admin'));
$this->next = 'error';
return;
}
$upgrader = $this->container->getUpgrader();
// regex optimization
preg_match('#([0-9]+\.[0-9]+)(?:\.[0-9]+){1,2}#', _PS_VERSION_, $matches);
$upgrader->channel = $this->container->getUpgradeConfiguration()->get('channel');
$upgrader->branch = $matches[1];
if ($this->container->getUpgradeConfiguration()->get('channel') == 'private' && !$this->container->getUpgradeConfiguration()->get('private_allow_major')) {
$upgrader->checkPSVersion(false, ['private', 'minor']);
} else {
$upgrader->checkPSVersion(false, ['minor']);
}
if ($upgrader->channel == 'private') {
$upgrader->link = $this->container->getUpgradeConfiguration()->get('private_release_link');
$upgrader->md5 = $this->container->getUpgradeConfiguration()->get('private_release_md5');
}
$this->logger->debug($this->translator->trans('Downloading from %s', [$upgrader->link], 'Modules.Autoupgrade.Admin'));
$this->logger->debug($this->translator->trans('File will be saved in %s', [$this->container->getFilePath()], 'Modules.Autoupgrade.Admin'));
if (file_exists($this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH))) {
FilesystemAdapter::deleteDirectory($this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH), false);
$this->logger->debug($this->translator->trans('Download directory has been emptied', [], 'Modules.Autoupgrade.Admin'));
}
$report = '';
$relative_download_path = str_replace(_PS_ROOT_DIR_, '', $this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH));
if (\ConfigurationTest::test_dir($relative_download_path, false, $report)) {
$res = $upgrader->downloadLast($this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH), $this->container->getProperty(UpgradeContainer::ARCHIVE_FILENAME));
if ($res) {
$md5file = md5_file(realpath($this->container->getProperty(UpgradeContainer::ARCHIVE_FILEPATH)));
if ($md5file == $upgrader->md5) {
$this->next = 'unzip';
$this->logger->debug($this->translator->trans('Download complete.', [], 'Modules.Autoupgrade.Admin'));
$this->logger->info($this->translator->trans('Download complete. Now extracting...', [], 'Modules.Autoupgrade.Admin'));
} else {
$this->logger->error($this->translator->trans('Download complete but MD5 sum does not match (%s).', [$md5file], 'Modules.Autoupgrade.Admin'));
$this->logger->info($this->translator->trans('Download complete but MD5 sum does not match (%s). Operation aborted.', [$md5file], 'Modules.Autoupgrade.Admin'));
$this->next = 'error';
}
} else {
if ($upgrader->channel == 'private') {
$this->logger->error($this->translator->trans('Error during download. The private key may be incorrect.', [], 'Modules.Autoupgrade.Admin'));
} else {
$this->logger->error($this->translator->trans('Error during download', [], 'Modules.Autoupgrade.Admin'));
}
$this->next = 'error';
}
} else {
$this->logger->error($this->translator->trans('Download directory %s is not writable.', [$this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH)], 'Modules.Autoupgrade.Admin'));
$this->next = 'error';
}
}
}