|
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; |
|
13
|
|
|
use gplcart\core\models\Translation; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Provides methods to backup modules |
|
17
|
|
|
*/ |
|
18
|
|
|
class Module |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Zip helper class instance |
|
22
|
|
|
* @var \gplcart\core\helpers\Zip $zip |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $zip; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Translation UI model instance |
|
28
|
|
|
* @var \gplcart\core\models\Translation $translation |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $translation; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Module constructor. |
|
34
|
|
|
* @param Translation $translation |
|
35
|
|
|
* @param Zip $zip |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(Translation $translation, Zip $zip) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->zip = $zip; |
|
40
|
|
|
$this->translation = $translation; |
|
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 = gplcart_file_private_module('backup'); |
|
52
|
|
|
|
|
53
|
|
|
if (!file_exists($directory) && !mkdir($directory, 0775, true)) { |
|
54
|
|
|
return false; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$data['type'] = 'module'; |
|
58
|
|
|
$data['name'] = $this->translation->text('Module @name', array('@name' => $data['name'])); |
|
59
|
|
|
|
|
60
|
|
|
$time = date('d-m-Y--G-i'); |
|
61
|
|
|
$destination = gplcart_file_unique("$directory/module-{$data['id']}-$time.zip"); |
|
62
|
|
|
$data['path'] = gplcart_file_relative($destination); |
|
63
|
|
|
|
|
64
|
|
|
$success = $this->zip->directory($data['directory'], $destination, $data['id']); |
|
65
|
|
|
|
|
66
|
|
|
if ($success) { |
|
67
|
|
|
return (bool) $model->add($data); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return false; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|