1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Backup |
5
|
|
|
* @author Iurii Makukh <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2015, Iurii Makukh |
7
|
|
|
* @license https://www.gnu.org/licenses/gpl.html GNU/GPLv3 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace gplcart\modules\backup\handlers; |
11
|
|
|
|
12
|
|
|
use gplcart\core\helpers\Zip as ZipHelper; |
13
|
|
|
use gplcart\core\models\Language as LanguageModel; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Provides methods to backup modules |
17
|
|
|
*/ |
18
|
|
|
class Module |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Language model instance |
23
|
|
|
* @var \gplcart\core\models\Language $language |
24
|
|
|
*/ |
25
|
|
|
protected $language; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Zip helper class instance |
29
|
|
|
* @var \gplcart\core\helpers\Zip $zip |
30
|
|
|
*/ |
31
|
|
|
protected $zip; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param LanguageModel $language |
35
|
|
|
* @param ZipHelper $zip |
36
|
|
|
*/ |
37
|
|
|
public function __construct(LanguageModel $language, ZipHelper $zip) |
38
|
|
|
{ |
39
|
|
|
$this->zip = $zip; |
40
|
|
|
$this->language = $language; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Creates a module backup |
45
|
|
|
* @param array $data |
46
|
|
|
* @param \gplcart\modules\backup\models\Backup $model |
47
|
|
|
* @return boolean |
48
|
|
|
*/ |
49
|
|
|
public function backup(array $data, $model) |
50
|
|
|
{ |
51
|
|
|
$directory = GC_PRIVATE_MODULE_DIR . '/backup'; |
52
|
|
|
if (!file_exists($directory) && !mkdir($directory, 0775, true)) { |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$data['type'] = 'module'; |
57
|
|
|
$data['name'] = $this->language->text('Module @name', array('@name' => $data['name'])); |
58
|
|
|
|
59
|
|
|
$time = date('d-m-Y--G-i'); |
60
|
|
|
$destination = gplcart_file_unique("$directory/module-{$data['id']}-$time.zip"); |
61
|
|
|
$data['path'] = gplcart_file_relative_path($destination); |
62
|
|
|
|
63
|
|
|
$success = $this->zip->folder($data['directory'], $destination, $data['id']); |
64
|
|
|
|
65
|
|
|
if ($success) { |
66
|
|
|
return (bool) $model->add($data); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|