1 | <?php |
||
28 | class Checkpoint { |
||
29 | |||
30 | const CORE_DIR = 'core'; |
||
31 | const THIRDPARTY_DIR = '3rdparty'; |
||
32 | const APP_DIR = 'apps'; |
||
33 | |||
34 | /** |
||
35 | * @var Locator $locator |
||
36 | */ |
||
37 | protected $locator; |
||
38 | |||
39 | /** |
||
40 | * @var Filesystemhelper $fsHelper |
||
41 | */ |
||
42 | protected $fsHelper; |
||
43 | |||
44 | /** |
||
45 | * |
||
46 | * @param Locator $locator |
||
47 | */ |
||
48 | 2 | public function __construct(Locator $locator, FilesystemHelper $fsHelper){ |
|
52 | |||
53 | public function create(){ |
||
54 | $checkpointName = $this->getCheckpointName(); |
||
55 | $checkpointPath = $this->locator->getCheckpointDir() . '/' . $checkpointName; |
||
56 | try{ |
||
57 | if (!$this->fsHelper->isWritable($this->locator->getCheckpointDir())){ |
||
58 | throw new \Exception($this->locator->getCheckpointDir() . ' is not writable.'); |
||
59 | } |
||
60 | $this->fsHelper->mkdir($checkpointPath); |
||
61 | |||
62 | $checkpointCorePath = $checkpointPath . '/' . self::CORE_DIR; |
||
63 | $this->fsHelper->mkdir($checkpointCorePath); |
||
64 | $core = $this->locator->getRootDirItems(); |
||
65 | foreach ($core as $coreItem){ |
||
66 | $cpItemPath = $checkpointCorePath . '/' . basename($coreItem); |
||
67 | $this->fsHelper->copyr($coreItem, $cpItemPath, true); |
||
68 | } |
||
69 | //copy config.php |
||
70 | $configDirSrc = $this->locator->getOwncloudRootPath() . '/config'; |
||
71 | $configDirDst = $checkpointCorePath . '/config'; |
||
72 | $this->fsHelper->copyr($configDirSrc, $configDirDst, true); |
||
73 | |||
74 | //copy 3rdparty |
||
75 | $this->fsHelper->copyr($this->locator->getOwncloudRootPath() . '/' . self::THIRDPARTY_DIR, $checkpointCorePath . '/' . self::THIRDPARTY_DIR, true); |
||
76 | |||
77 | $checkpointAppPath = $checkpointPath . '/' . self::APP_DIR; |
||
78 | $this->fsHelper->mkdir($checkpointAppPath); |
||
79 | $appManager = Application::$container['utils.appmanager']; |
||
80 | $apps = $appManager->getAllApps(); |
||
81 | foreach ($apps as $appId){ |
||
82 | $appPath = $appManager->getAppPath($appId); |
||
83 | if ($appPath){ |
||
84 | $this->fsHelper->copyr($appPath, $checkpointAppPath . '/' . $appId, true); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | } catch (\Exception $e){ |
||
89 | $application = Application::$container['application']; |
||
90 | $application->getLogger()->error($e->getMessage()); |
||
91 | $this->fsHelper->removeIfExists($checkpointPath); |
||
92 | throw $e; |
||
93 | } |
||
94 | return $checkpointName; |
||
95 | } |
||
96 | |||
97 | public function restore($checkpointId){ |
||
107 | |||
108 | 2 | public function getAll(){ |
|
109 | 2 | $checkpointDir = $this->locator->getCheckpointDir(); |
|
110 | 2 | $content = $this->fsHelper->isDir($checkpointDir) ? $this->fsHelper->scandir($checkpointDir) : []; |
|
111 | 2 | $checkpoints = array_filter( |
|
112 | $content, |
||
113 | 2 | function($dir){ |
|
114 | 1 | return !in_array($dir, ['.', '..']); |
|
115 | 2 | } |
|
116 | ); |
||
117 | 2 | return $checkpoints; |
|
118 | } |
||
119 | |||
120 | protected function getCheckpointName(){ |
||
124 | |||
125 | } |
||
126 |