1 | <?php |
||
13 | class CloudControl |
||
14 | { |
||
15 | /** |
||
16 | * @param string $rootDir |
||
17 | * @param string $configPath |
||
18 | */ |
||
19 | public static function run($rootDir, $configPath) |
||
20 | { |
||
21 | new Application($rootDir, $configPath); |
||
22 | } |
||
23 | |||
24 | public static function postInstall(Event $event) |
||
25 | { |
||
26 | $event->getIO()->write("Post install"); |
||
27 | self::checkInstall($event); |
||
28 | } |
||
29 | |||
30 | public static function postUpdate(Event $event) |
||
31 | { |
||
32 | $event->getIO()->write("Post update"); |
||
33 | self::checkInstall($event); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @param Event $event |
||
38 | */ |
||
39 | private static function checkInstall(Event $event) |
||
40 | { |
||
41 | $event->getIO()->write(""); |
||
42 | $event->getIO()->write("********************************************************"); |
||
43 | $event->getIO()->write("*** Checking installation of Cloud Control framework ***"); |
||
44 | $event->getIO()->write("********************************************************"); |
||
45 | $event->getIO()->write(""); |
||
46 | |||
47 | $vendorDir = $event->getComposer()->getConfig()->get('vendor-dir'); |
||
48 | $rootDir = realpath($vendorDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); |
||
49 | |||
50 | $baseConfigTargetPath = $rootDir . DIRECTORY_SEPARATOR . 'config.json'; |
||
51 | $configObject = self::getConfig($event, $baseConfigTargetPath); |
||
52 | |||
53 | $configObject->{'templateDir'} = self::createDir($event, $rootDir, 'templates'); |
||
54 | $configObject->{'storageDir'} = self::createDir($event, $rootDir, $configObject->{'storageDir'}); |
||
55 | $configObject->{'publicDir'} = self::createDir($event, $rootDir, 'public'); |
||
56 | $configObject->{'jsDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'js'); |
||
57 | $configObject->{'cssDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'css'); |
||
58 | $configObject->{'imagesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'images'); |
||
59 | $configObject->{'filesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'files'); |
||
60 | $componentsDir = self::createDir($event, $rootDir, 'components'); |
||
61 | |||
62 | $baseStorageDefaultPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.json'; |
||
63 | $baseStorageSqlPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.sql'; |
||
64 | $baseCacheSqlPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_cache.sql'; |
||
65 | |||
66 | self::createStorage($configObject->{'storageDir'}, $baseStorageDefaultPath, $baseStorageSqlPath); |
||
67 | self::createCacheStorage($rootDir . DIRECTORY_SEPARATOR . $configObject->{'storageDir'}, $baseCacheSqlPath); |
||
68 | self::saveConfig($event, $baseConfigTargetPath, $configObject); |
||
69 | self::copyInstallFile($event, 'public.htaccess', $configObject->{'publicDir'}, '.htaccess'); |
||
70 | self::copyInstallFile($event, 'root.htaccess', $rootDir, '.htaccess'); |
||
71 | self::copyInstallFile($event, 'base.php', $configObject->{'templateDir'}); |
||
72 | self::copyInstallFile($event, 'cms.css', $configObject->{'cssDir'}); |
||
73 | self::copyInstallFile($event, 'cms.js', $configObject->{'jsDir'}); |
||
74 | self::copyInstallFile($event, 'index.php', $configObject->{'publicDir'}); |
||
75 | self::copyInstallFile($event, 'CustomComponent.php', $componentsDir); |
||
76 | |||
77 | $event->getIO()->write(""); |
||
78 | $event->getIO()->write("[SUCCESS] Installation is complete"); |
||
79 | $event->getIO()->write(""); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @param Event $event |
||
84 | * @param $baseConfigTargetPath |
||
85 | * @param $configObject |
||
86 | */ |
||
87 | private static function saveConfig(Event $event, $baseConfigTargetPath, $configObject) |
||
92 | |||
93 | private static function copyInstallFile(Event $event, $sourceFileName, $destinationPath, $destinationFileName = null) |
||
114 | |||
115 | /** |
||
116 | * @param $storageDir |
||
117 | * @param $baseStorageDefaultPath |
||
118 | * @param $baseStorageSqlPath |
||
119 | */ |
||
120 | private static function createStorage($storageDir, $baseStorageDefaultPath, $baseStorageSqlPath) |
||
125 | |||
126 | private static function createDir(Event $event, $rootDir, $dirName) |
||
127 | { |
||
128 | $dir = $rootDir . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR; |
||
129 | if (!is_dir($dir)) { |
||
139 | |||
140 | /** |
||
141 | * @param $configTargetPath |
||
142 | * @return mixed |
||
143 | */ |
||
144 | private static function getConfig(Event $event, $configTargetPath) |
||
157 | |||
158 | /** |
||
159 | * Calculate the relative path from $from to $to |
||
160 | * Derived from https://stackoverflow.com/a/2638272/ |
||
161 | * |
||
162 | * @param $from |
||
163 | * @param $to |
||
164 | * @return string |
||
165 | */ |
||
166 | private static function getRelativePath($from, $to) |
||
183 | |||
184 | /** |
||
185 | * @param $relPath |
||
186 | * @return mixed |
||
187 | */ |
||
188 | private static function removePointerToCurrentDir($relPath) |
||
195 | |||
196 | /** |
||
197 | * @param $from |
||
198 | * @param $to |
||
199 | * @param $relPath |
||
200 | * @return array |
||
201 | */ |
||
202 | private static function calculateRelativePath($from, $to, $relPath) |
||
224 | |||
225 | private static function createCacheStorage($storageDir, $baseCacheSqlPath) |
||
230 | |||
231 | } |