@@ -9,15 +9,15 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | function dump() |
| 11 | 11 | { |
| 12 | - $debug_backtrace = current(debug_backtrace()); |
|
| 13 | - if (PHP_SAPI == 'cli') { |
|
| 14 | - echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
| 15 | - foreach (func_get_args() as $data) { |
|
| 16 | - var_dump($data); |
|
| 17 | - } |
|
| 18 | - } else { |
|
| 19 | - ob_clean(); |
|
| 20 | - echo <<<END |
|
| 12 | + $debug_backtrace = current(debug_backtrace()); |
|
| 13 | + if (PHP_SAPI == 'cli') { |
|
| 14 | + echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
| 15 | + foreach (func_get_args() as $data) { |
|
| 16 | + var_dump($data); |
|
| 17 | + } |
|
| 18 | + } else { |
|
| 19 | + ob_clean(); |
|
| 20 | + echo <<<END |
|
| 21 | 21 | <!DOCTYPE html> |
| 22 | 22 | <html> |
| 23 | 23 | <head> |
@@ -29,20 +29,20 @@ discard block |
||
| 29 | 29 | <body> |
| 30 | 30 | END; |
| 31 | 31 | |
| 32 | - echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
| 33 | - echo '<pre>'; |
|
| 34 | - foreach (func_get_args() as $data) { |
|
| 35 | - echo "<code>"; |
|
| 36 | - var_dump($data); |
|
| 37 | - echo "</code>"; |
|
| 38 | - } |
|
| 39 | - echo '</pre>'; |
|
| 40 | - echo <<<END |
|
| 32 | + echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
| 33 | + echo '<pre>'; |
|
| 34 | + foreach (func_get_args() as $data) { |
|
| 35 | + echo "<code>"; |
|
| 36 | + var_dump($data); |
|
| 37 | + echo "</code>"; |
|
| 38 | + } |
|
| 39 | + echo '</pre>'; |
|
| 40 | + echo <<<END |
|
| 41 | 41 | </body> |
| 42 | 42 | </html> |
| 43 | 43 | END; |
| 44 | - } |
|
| 45 | - die; |
|
| 44 | + } |
|
| 45 | + die; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -53,27 +53,27 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | function sanitize_output($buffer) |
| 55 | 55 | { |
| 56 | - if (!isset($_GET['unsanitized'])) { |
|
| 57 | - $search = array( |
|
| 58 | - '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
| 59 | - '/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
| 60 | - '/(\s)+/s', // shorten multiple whitespace sequences |
|
| 61 | - '/<!--(.|\s)*?-->/' // Remove HTML comments |
|
| 62 | - ); |
|
| 56 | + if (!isset($_GET['unsanitized'])) { |
|
| 57 | + $search = array( |
|
| 58 | + '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
| 59 | + '/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
| 60 | + '/(\s)+/s', // shorten multiple whitespace sequences |
|
| 61 | + '/<!--(.|\s)*?-->/' // Remove HTML comments |
|
| 62 | + ); |
|
| 63 | 63 | |
| 64 | - $replace = array( |
|
| 65 | - '>', |
|
| 66 | - '<', |
|
| 67 | - '\\1', |
|
| 68 | - '' |
|
| 69 | - ); |
|
| 64 | + $replace = array( |
|
| 65 | + '>', |
|
| 66 | + '<', |
|
| 67 | + '\\1', |
|
| 68 | + '' |
|
| 69 | + ); |
|
| 70 | 70 | |
| 71 | - $buffer = preg_replace($search, $replace, $buffer); |
|
| 71 | + $buffer = preg_replace($search, $replace, $buffer); |
|
| 72 | 72 | |
| 73 | - return $buffer; |
|
| 74 | - } else { |
|
| 75 | - return $buffer; |
|
| 76 | - } |
|
| 73 | + return $buffer; |
|
| 74 | + } else { |
|
| 75 | + return $buffer; |
|
| 76 | + } |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -85,13 +85,13 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | function utf8Convert($array) |
| 87 | 87 | { |
| 88 | - array_walk_recursive($array, function (&$item) { |
|
| 89 | - if (!mb_detect_encoding($item, 'utf-8', true)) { |
|
| 90 | - $item = utf8_encode($item); |
|
| 91 | - } |
|
| 92 | - }); |
|
| 88 | + array_walk_recursive($array, function (&$item) { |
|
| 89 | + if (!mb_detect_encoding($item, 'utf-8', true)) { |
|
| 90 | + $item = utf8_encode($item); |
|
| 91 | + } |
|
| 92 | + }); |
|
| 93 | 93 | |
| 94 | - return $array; |
|
| 94 | + return $array; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -104,37 +104,37 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | function getRelativePath($from, $to) |
| 106 | 106 | { |
| 107 | - // some compatibility fixes for Windows paths |
|
| 108 | - $from = is_dir($from) ? rtrim($from, '\/') . DIRECTORY_SEPARATOR : $from; |
|
| 109 | - $to = is_dir($to) ? rtrim($to, '\/') . DIRECTORY_SEPARATOR : $to; |
|
| 110 | - $from = str_replace('\\', DIRECTORY_SEPARATOR, $from); |
|
| 111 | - $to = str_replace('\\', DIRECTORY_SEPARATOR, $to); |
|
| 107 | + // some compatibility fixes for Windows paths |
|
| 108 | + $from = is_dir($from) ? rtrim($from, '\/') . DIRECTORY_SEPARATOR : $from; |
|
| 109 | + $to = is_dir($to) ? rtrim($to, '\/') . DIRECTORY_SEPARATOR : $to; |
|
| 110 | + $from = str_replace('\\', DIRECTORY_SEPARATOR, $from); |
|
| 111 | + $to = str_replace('\\', DIRECTORY_SEPARATOR, $to); |
|
| 112 | 112 | |
| 113 | - $from = explode(DIRECTORY_SEPARATOR, $from); |
|
| 114 | - $to = explode(DIRECTORY_SEPARATOR, $to); |
|
| 115 | - $relPath = $to; |
|
| 113 | + $from = explode(DIRECTORY_SEPARATOR, $from); |
|
| 114 | + $to = explode(DIRECTORY_SEPARATOR, $to); |
|
| 115 | + $relPath = $to; |
|
| 116 | 116 | |
| 117 | - foreach ($from as $depth => $dir) { |
|
| 118 | - // find first non-matching dir |
|
| 119 | - if ($dir === $to[$depth]) { |
|
| 120 | - // ignore this directory |
|
| 121 | - array_shift($relPath); |
|
| 122 | - } else { |
|
| 123 | - // get number of remaining dirs to $from |
|
| 124 | - $remaining = count($from) - $depth; |
|
| 125 | - if ($remaining > 1) { |
|
| 126 | - // add traversals up to first matching dir |
|
| 127 | - $padLength = (count($relPath) + $remaining - 1) * -1; |
|
| 128 | - $relPath = array_pad($relPath, $padLength, '..'); |
|
| 129 | - break; |
|
| 130 | - } else { |
|
| 131 | - $relPath[0] = '.' . DIRECTORY_SEPARATOR . $relPath[0]; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - $relPath = implode(DIRECTORY_SEPARATOR, $relPath); |
|
| 136 | - while (strpos($relPath, '.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR) !== false) { |
|
| 137 | - $relPath = str_replace('.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR, '.' . DIRECTORY_SEPARATOR, $relPath); |
|
| 138 | - } |
|
| 139 | - return $relPath; |
|
| 117 | + foreach ($from as $depth => $dir) { |
|
| 118 | + // find first non-matching dir |
|
| 119 | + if ($dir === $to[$depth]) { |
|
| 120 | + // ignore this directory |
|
| 121 | + array_shift($relPath); |
|
| 122 | + } else { |
|
| 123 | + // get number of remaining dirs to $from |
|
| 124 | + $remaining = count($from) - $depth; |
|
| 125 | + if ($remaining > 1) { |
|
| 126 | + // add traversals up to first matching dir |
|
| 127 | + $padLength = (count($relPath) + $remaining - 1) * -1; |
|
| 128 | + $relPath = array_pad($relPath, $padLength, '..'); |
|
| 129 | + break; |
|
| 130 | + } else { |
|
| 131 | + $relPath[0] = '.' . DIRECTORY_SEPARATOR . $relPath[0]; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + $relPath = implode(DIRECTORY_SEPARATOR, $relPath); |
|
| 136 | + while (strpos($relPath, '.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR) !== false) { |
|
| 137 | + $relPath = str_replace('.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR, '.' . DIRECTORY_SEPARATOR, $relPath); |
|
| 138 | + } |
|
| 139 | + return $relPath; |
|
| 140 | 140 | } |
| 141 | 141 | \ No newline at end of file |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | { |
| 12 | 12 | $debug_backtrace = current(debug_backtrace()); |
| 13 | 13 | if (PHP_SAPI == 'cli') { |
| 14 | - echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
| 14 | + echo 'Dump: '.$debug_backtrace['file'].':'.$debug_backtrace['line']."\n"; |
|
| 15 | 15 | foreach (func_get_args() as $data) { |
| 16 | 16 | var_dump($data); |
| 17 | 17 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | <body> |
| 30 | 30 | END; |
| 31 | 31 | |
| 32 | - echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
| 32 | + echo '<div>Dump: '.$debug_backtrace['file'].':<b>'.$debug_backtrace['line']."</b></div>"; |
|
| 33 | 33 | echo '<pre>'; |
| 34 | 34 | foreach (func_get_args() as $data) { |
| 35 | 35 | echo "<code>"; |
@@ -55,9 +55,9 @@ discard block |
||
| 55 | 55 | { |
| 56 | 56 | if (!isset($_GET['unsanitized'])) { |
| 57 | 57 | $search = array( |
| 58 | - '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
| 59 | - '/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
| 60 | - '/(\s)+/s', // shorten multiple whitespace sequences |
|
| 58 | + '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
| 59 | + '/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
| 60 | + '/(\s)+/s', // shorten multiple whitespace sequences |
|
| 61 | 61 | '/<!--(.|\s)*?-->/' // Remove HTML comments |
| 62 | 62 | ); |
| 63 | 63 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | function utf8Convert($array) |
| 87 | 87 | { |
| 88 | - array_walk_recursive($array, function (&$item) { |
|
| 88 | + array_walk_recursive($array, function(&$item) { |
|
| 89 | 89 | if (!mb_detect_encoding($item, 'utf-8', true)) { |
| 90 | 90 | $item = utf8_encode($item); |
| 91 | 91 | } |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | function getRelativePath($from, $to) |
| 106 | 106 | { |
| 107 | 107 | // some compatibility fixes for Windows paths |
| 108 | - $from = is_dir($from) ? rtrim($from, '\/') . DIRECTORY_SEPARATOR : $from; |
|
| 109 | - $to = is_dir($to) ? rtrim($to, '\/') . DIRECTORY_SEPARATOR : $to; |
|
| 108 | + $from = is_dir($from) ? rtrim($from, '\/').DIRECTORY_SEPARATOR : $from; |
|
| 109 | + $to = is_dir($to) ? rtrim($to, '\/').DIRECTORY_SEPARATOR : $to; |
|
| 110 | 110 | $from = str_replace('\\', DIRECTORY_SEPARATOR, $from); |
| 111 | 111 | $to = str_replace('\\', DIRECTORY_SEPARATOR, $to); |
| 112 | 112 | |
@@ -128,13 +128,13 @@ discard block |
||
| 128 | 128 | $relPath = array_pad($relPath, $padLength, '..'); |
| 129 | 129 | break; |
| 130 | 130 | } else { |
| 131 | - $relPath[0] = '.' . DIRECTORY_SEPARATOR . $relPath[0]; |
|
| 131 | + $relPath[0] = '.'.DIRECTORY_SEPARATOR.$relPath[0]; |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | $relPath = implode(DIRECTORY_SEPARATOR, $relPath); |
| 136 | - while (strpos($relPath, '.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR) !== false) { |
|
| 137 | - $relPath = str_replace('.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR, '.' . DIRECTORY_SEPARATOR, $relPath); |
|
| 136 | + while (strpos($relPath, '.'.DIRECTORY_SEPARATOR.'.'.DIRECTORY_SEPARATOR) !== false) { |
|
| 137 | + $relPath = str_replace('.'.DIRECTORY_SEPARATOR.'.'.DIRECTORY_SEPARATOR, '.'.DIRECTORY_SEPARATOR, $relPath); |
|
| 138 | 138 | } |
| 139 | 139 | return $relPath; |
| 140 | 140 | } |
| 141 | 141 | \ No newline at end of file |
@@ -11,150 +11,150 @@ |
||
| 11 | 11 | |
| 12 | 12 | class CloudControl |
| 13 | 13 | { |
| 14 | - public static function run() |
|
| 15 | - { |
|
| 16 | - new Application(); |
|
| 17 | - } |
|
| 18 | - |
|
| 19 | - public static function postInstall(Event $event) |
|
| 20 | - { |
|
| 21 | - $event->getIO()->write("Post install"); |
|
| 22 | - self::checkInstall($event); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public static function postUpdate(Event $event) |
|
| 26 | - { |
|
| 27 | - $event->getIO()->write("Post update"); |
|
| 28 | - self::checkInstall($event); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @param Event $event |
|
| 33 | - */ |
|
| 34 | - private static function checkInstall(Event $event) |
|
| 35 | - { |
|
| 36 | - if (!function_exists('getRelativePath')) { |
|
| 37 | - require_once(__DIR__ . DIRECTORY_SEPARATOR . 'util' . DIRECTORY_SEPARATOR . 'functions.php'); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - $event->getIO()->write(""); |
|
| 41 | - $event->getIO()->write("********************************************************"); |
|
| 42 | - $event->getIO()->write("*** Checking installation of Cloud Control framework ***"); |
|
| 43 | - $event->getIO()->write("********************************************************"); |
|
| 44 | - $event->getIO()->write(""); |
|
| 45 | - |
|
| 46 | - $vendorDir = $event->getComposer()->getConfig()->get('vendor-dir'); |
|
| 47 | - $rootDir = realpath($vendorDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); |
|
| 48 | - |
|
| 49 | - $baseConfigTargetPath = $rootDir . DIRECTORY_SEPARATOR . 'config.json'; |
|
| 50 | - $configObject = self::getConfig($event, $baseConfigTargetPath); |
|
| 51 | - |
|
| 52 | - $configObject->{'vendorDir'} = realpath($vendorDir); |
|
| 53 | - $configObject->{'rootDir'} = $rootDir; |
|
| 54 | - $configObject->{'templateDir'} = self::createDir($event, $rootDir, 'templates'); |
|
| 55 | - $configObject->{'storageDir'} = self::createDir($event, $rootDir, $configObject->{'storageDir'}); |
|
| 56 | - $configObject->{'publicDir'} = self::createDir($event, $rootDir, 'public'); |
|
| 57 | - $configObject->{'jsDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'js'); |
|
| 58 | - $configObject->{'cssDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'css'); |
|
| 59 | - $configObject->{'imagesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'images'); |
|
| 60 | - $configObject->{'filesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'files'); |
|
| 61 | - |
|
| 62 | - $baseStorageDefaultPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.json'; |
|
| 63 | - $baseStorageSqlPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.sql'; |
|
| 64 | - |
|
| 65 | - self::createStorage($configObject->{'storageDir'}, $baseStorageDefaultPath, $baseStorageSqlPath); |
|
| 66 | - self::saveConfig($event, $baseConfigTargetPath, $configObject); |
|
| 67 | - self::copyInstallFile($event, 'public.htaccess', $configObject->{'publicDir'}, '.htaccess'); |
|
| 68 | - self::copyInstallFile($event, 'root.htaccess', $configObject->{'rootDir'}, '.htaccess'); |
|
| 69 | - self::copyInstallFile($event, 'base.php', $configObject->{'templateDir'}); |
|
| 70 | - self::copyInstallFile($event, 'cms.css', $configObject->{'cssDir'}); |
|
| 71 | - self::copyInstallFile($event, 'cms.js', $configObject->{'jsDir'}); |
|
| 72 | - self::copyInstallFile($event, 'index.php', $configObject->{'publicDir'}); |
|
| 73 | - |
|
| 74 | - $event->getIO()->write(""); |
|
| 75 | - $event->getIO()->write("[SUCCESS] Installation is complete"); |
|
| 76 | - $event->getIO()->write(""); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param Event $event |
|
| 81 | - * @param $baseConfigTargetPath |
|
| 82 | - * @param $configObject |
|
| 83 | - * @internal param $rootDir |
|
| 84 | - * @internal param $vendorDir |
|
| 85 | - * @internal param $templateDir |
|
| 86 | - * @internal param $storageDir |
|
| 87 | - * @internal param $baseConfigDefaultPath |
|
| 88 | - * @internal param $baseConfigTargetPath |
|
| 89 | - * @internal param $storageDir |
|
| 90 | - */ |
|
| 91 | - private static function saveConfig(Event $event, $baseConfigTargetPath, $configObject) |
|
| 92 | - { |
|
| 93 | - file_put_contents($baseConfigTargetPath, json_encode($configObject)); |
|
| 94 | - $event->getIO()->write("[INFO] Saved config to: " . $baseConfigTargetPath); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - private static function copyInstallFile(Event $event, $sourceFileName, $destinationPath, $destinationFileName = null) |
|
| 98 | - { |
|
| 99 | - $sourceFilePath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install/_' . $sourceFileName); |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - if ($destinationFileName === null) { |
|
| 103 | - $destinationFileName = $sourceFileName; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if (file_exists($sourceFilePath) && realpath($destinationPath) !== false) { |
|
| 107 | - $destinationFullPath = realpath($destinationPath) . DIRECTORY_SEPARATOR . $destinationFileName; |
|
| 108 | - if (file_exists($destinationFullPath)) { |
|
| 109 | - $event->getIO()->write("[INFO] File already exists: " . $destinationFullPath); |
|
| 110 | - } else { |
|
| 111 | - copy($sourceFilePath, $destinationFullPath); |
|
| 112 | - $event->getIO()->write("[INSTALL] Copied file: " . $sourceFileName . ' to ' . $destinationPath); |
|
| 113 | - } |
|
| 114 | - } else { |
|
| 115 | - $event->getIO()->write("[ERROR] Couldnt copy file: " . $sourceFileName . ' to ' . $destinationPath); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @param $storageDir |
|
| 121 | - * @param $baseStorageDefaultPath |
|
| 122 | - * @param $baseStorageSqlPath |
|
| 123 | - */ |
|
| 124 | - private static function createStorage($storageDir, $baseStorageDefaultPath, $baseStorageSqlPath) |
|
| 125 | - { |
|
| 126 | - $repository = new Repository($storageDir); |
|
| 127 | - $repository->init($baseStorageDefaultPath, $baseStorageSqlPath); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - private static function createDir(Event $event, $rootDir, $dirName) |
|
| 131 | - { |
|
| 132 | - $dir = $rootDir . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR; |
|
| 133 | - if (!is_dir($dir)) { |
|
| 134 | - mkdir($dir); |
|
| 135 | - $event->getIO()->write("[INSTALL] Created dir: " . $dir); |
|
| 136 | - } else { |
|
| 137 | - $event->getIO()->write("[INFO] Dir already exists: " . $dir); |
|
| 138 | - } |
|
| 139 | - return \getRelativePath($rootDir, $dir); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param $configTargetPath |
|
| 144 | - * @return mixed |
|
| 145 | - */ |
|
| 146 | - private static function getConfig(Event $event, $configTargetPath) |
|
| 147 | - { |
|
| 148 | - $baseConfigDefaultPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_config.json'); |
|
| 149 | - |
|
| 150 | - if (file_exists($configTargetPath)) { |
|
| 151 | - $config = json_decode(file_get_contents($configTargetPath)); |
|
| 152 | - $event->getIO()->write("[INFO] Using existing config"); |
|
| 153 | - } else { |
|
| 154 | - $config = json_decode(file_get_contents($baseConfigDefaultPath)); |
|
| 155 | - $event->getIO()->write("[INSTALL] Created default config"); |
|
| 156 | - } |
|
| 157 | - return $config; |
|
| 158 | - } |
|
| 14 | + public static function run() |
|
| 15 | + { |
|
| 16 | + new Application(); |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + public static function postInstall(Event $event) |
|
| 20 | + { |
|
| 21 | + $event->getIO()->write("Post install"); |
|
| 22 | + self::checkInstall($event); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public static function postUpdate(Event $event) |
|
| 26 | + { |
|
| 27 | + $event->getIO()->write("Post update"); |
|
| 28 | + self::checkInstall($event); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @param Event $event |
|
| 33 | + */ |
|
| 34 | + private static function checkInstall(Event $event) |
|
| 35 | + { |
|
| 36 | + if (!function_exists('getRelativePath')) { |
|
| 37 | + require_once(__DIR__ . DIRECTORY_SEPARATOR . 'util' . DIRECTORY_SEPARATOR . 'functions.php'); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + $event->getIO()->write(""); |
|
| 41 | + $event->getIO()->write("********************************************************"); |
|
| 42 | + $event->getIO()->write("*** Checking installation of Cloud Control framework ***"); |
|
| 43 | + $event->getIO()->write("********************************************************"); |
|
| 44 | + $event->getIO()->write(""); |
|
| 45 | + |
|
| 46 | + $vendorDir = $event->getComposer()->getConfig()->get('vendor-dir'); |
|
| 47 | + $rootDir = realpath($vendorDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); |
|
| 48 | + |
|
| 49 | + $baseConfigTargetPath = $rootDir . DIRECTORY_SEPARATOR . 'config.json'; |
|
| 50 | + $configObject = self::getConfig($event, $baseConfigTargetPath); |
|
| 51 | + |
|
| 52 | + $configObject->{'vendorDir'} = realpath($vendorDir); |
|
| 53 | + $configObject->{'rootDir'} = $rootDir; |
|
| 54 | + $configObject->{'templateDir'} = self::createDir($event, $rootDir, 'templates'); |
|
| 55 | + $configObject->{'storageDir'} = self::createDir($event, $rootDir, $configObject->{'storageDir'}); |
|
| 56 | + $configObject->{'publicDir'} = self::createDir($event, $rootDir, 'public'); |
|
| 57 | + $configObject->{'jsDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'js'); |
|
| 58 | + $configObject->{'cssDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'css'); |
|
| 59 | + $configObject->{'imagesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'images'); |
|
| 60 | + $configObject->{'filesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'files'); |
|
| 61 | + |
|
| 62 | + $baseStorageDefaultPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.json'; |
|
| 63 | + $baseStorageSqlPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.sql'; |
|
| 64 | + |
|
| 65 | + self::createStorage($configObject->{'storageDir'}, $baseStorageDefaultPath, $baseStorageSqlPath); |
|
| 66 | + self::saveConfig($event, $baseConfigTargetPath, $configObject); |
|
| 67 | + self::copyInstallFile($event, 'public.htaccess', $configObject->{'publicDir'}, '.htaccess'); |
|
| 68 | + self::copyInstallFile($event, 'root.htaccess', $configObject->{'rootDir'}, '.htaccess'); |
|
| 69 | + self::copyInstallFile($event, 'base.php', $configObject->{'templateDir'}); |
|
| 70 | + self::copyInstallFile($event, 'cms.css', $configObject->{'cssDir'}); |
|
| 71 | + self::copyInstallFile($event, 'cms.js', $configObject->{'jsDir'}); |
|
| 72 | + self::copyInstallFile($event, 'index.php', $configObject->{'publicDir'}); |
|
| 73 | + |
|
| 74 | + $event->getIO()->write(""); |
|
| 75 | + $event->getIO()->write("[SUCCESS] Installation is complete"); |
|
| 76 | + $event->getIO()->write(""); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param Event $event |
|
| 81 | + * @param $baseConfigTargetPath |
|
| 82 | + * @param $configObject |
|
| 83 | + * @internal param $rootDir |
|
| 84 | + * @internal param $vendorDir |
|
| 85 | + * @internal param $templateDir |
|
| 86 | + * @internal param $storageDir |
|
| 87 | + * @internal param $baseConfigDefaultPath |
|
| 88 | + * @internal param $baseConfigTargetPath |
|
| 89 | + * @internal param $storageDir |
|
| 90 | + */ |
|
| 91 | + private static function saveConfig(Event $event, $baseConfigTargetPath, $configObject) |
|
| 92 | + { |
|
| 93 | + file_put_contents($baseConfigTargetPath, json_encode($configObject)); |
|
| 94 | + $event->getIO()->write("[INFO] Saved config to: " . $baseConfigTargetPath); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + private static function copyInstallFile(Event $event, $sourceFileName, $destinationPath, $destinationFileName = null) |
|
| 98 | + { |
|
| 99 | + $sourceFilePath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install/_' . $sourceFileName); |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + if ($destinationFileName === null) { |
|
| 103 | + $destinationFileName = $sourceFileName; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if (file_exists($sourceFilePath) && realpath($destinationPath) !== false) { |
|
| 107 | + $destinationFullPath = realpath($destinationPath) . DIRECTORY_SEPARATOR . $destinationFileName; |
|
| 108 | + if (file_exists($destinationFullPath)) { |
|
| 109 | + $event->getIO()->write("[INFO] File already exists: " . $destinationFullPath); |
|
| 110 | + } else { |
|
| 111 | + copy($sourceFilePath, $destinationFullPath); |
|
| 112 | + $event->getIO()->write("[INSTALL] Copied file: " . $sourceFileName . ' to ' . $destinationPath); |
|
| 113 | + } |
|
| 114 | + } else { |
|
| 115 | + $event->getIO()->write("[ERROR] Couldnt copy file: " . $sourceFileName . ' to ' . $destinationPath); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @param $storageDir |
|
| 121 | + * @param $baseStorageDefaultPath |
|
| 122 | + * @param $baseStorageSqlPath |
|
| 123 | + */ |
|
| 124 | + private static function createStorage($storageDir, $baseStorageDefaultPath, $baseStorageSqlPath) |
|
| 125 | + { |
|
| 126 | + $repository = new Repository($storageDir); |
|
| 127 | + $repository->init($baseStorageDefaultPath, $baseStorageSqlPath); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + private static function createDir(Event $event, $rootDir, $dirName) |
|
| 131 | + { |
|
| 132 | + $dir = $rootDir . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR; |
|
| 133 | + if (!is_dir($dir)) { |
|
| 134 | + mkdir($dir); |
|
| 135 | + $event->getIO()->write("[INSTALL] Created dir: " . $dir); |
|
| 136 | + } else { |
|
| 137 | + $event->getIO()->write("[INFO] Dir already exists: " . $dir); |
|
| 138 | + } |
|
| 139 | + return \getRelativePath($rootDir, $dir); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param $configTargetPath |
|
| 144 | + * @return mixed |
|
| 145 | + */ |
|
| 146 | + private static function getConfig(Event $event, $configTargetPath) |
|
| 147 | + { |
|
| 148 | + $baseConfigDefaultPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_config.json'); |
|
| 149 | + |
|
| 150 | + if (file_exists($configTargetPath)) { |
|
| 151 | + $config = json_decode(file_get_contents($configTargetPath)); |
|
| 152 | + $event->getIO()->write("[INFO] Using existing config"); |
|
| 153 | + } else { |
|
| 154 | + $config = json_decode(file_get_contents($baseConfigDefaultPath)); |
|
| 155 | + $event->getIO()->write("[INSTALL] Created default config"); |
|
| 156 | + } |
|
| 157 | + return $config; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | 160 | } |
| 161 | 161 | \ No newline at end of file |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | private static function checkInstall(Event $event) |
| 35 | 35 | { |
| 36 | 36 | if (!function_exists('getRelativePath')) { |
| 37 | - require_once(__DIR__ . DIRECTORY_SEPARATOR . 'util' . DIRECTORY_SEPARATOR . 'functions.php'); |
|
| 37 | + require_once(__DIR__.DIRECTORY_SEPARATOR.'util'.DIRECTORY_SEPARATOR.'functions.php'); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $event->getIO()->write(""); |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | $event->getIO()->write(""); |
| 45 | 45 | |
| 46 | 46 | $vendorDir = $event->getComposer()->getConfig()->get('vendor-dir'); |
| 47 | - $rootDir = realpath($vendorDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); |
|
| 47 | + $rootDir = realpath($vendorDir.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR); |
|
| 48 | 48 | |
| 49 | - $baseConfigTargetPath = $rootDir . DIRECTORY_SEPARATOR . 'config.json'; |
|
| 49 | + $baseConfigTargetPath = $rootDir.DIRECTORY_SEPARATOR.'config.json'; |
|
| 50 | 50 | $configObject = self::getConfig($event, $baseConfigTargetPath); |
| 51 | 51 | |
| 52 | 52 | $configObject->{'vendorDir'} = realpath($vendorDir); |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | $configObject->{'templateDir'} = self::createDir($event, $rootDir, 'templates'); |
| 55 | 55 | $configObject->{'storageDir'} = self::createDir($event, $rootDir, $configObject->{'storageDir'}); |
| 56 | 56 | $configObject->{'publicDir'} = self::createDir($event, $rootDir, 'public'); |
| 57 | - $configObject->{'jsDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'js'); |
|
| 58 | - $configObject->{'cssDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'css'); |
|
| 59 | - $configObject->{'imagesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'images'); |
|
| 60 | - $configObject->{'filesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'} . 'files'); |
|
| 57 | + $configObject->{'jsDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'}.'js'); |
|
| 58 | + $configObject->{'cssDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'}.'css'); |
|
| 59 | + $configObject->{'imagesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'}.'images'); |
|
| 60 | + $configObject->{'filesDir'} = self::createDir($event, $rootDir, $configObject->{'publicDir'}.'files'); |
|
| 61 | 61 | |
| 62 | - $baseStorageDefaultPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.json'; |
|
| 63 | - $baseStorageSqlPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.sql'; |
|
| 62 | + $baseStorageDefaultPath = __DIR__.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'_storage.json'; |
|
| 63 | + $baseStorageSqlPath = __DIR__.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'_storage.sql'; |
|
| 64 | 64 | |
| 65 | 65 | self::createStorage($configObject->{'storageDir'}, $baseStorageDefaultPath, $baseStorageSqlPath); |
| 66 | 66 | self::saveConfig($event, $baseConfigTargetPath, $configObject); |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | private static function saveConfig(Event $event, $baseConfigTargetPath, $configObject) |
| 92 | 92 | { |
| 93 | 93 | file_put_contents($baseConfigTargetPath, json_encode($configObject)); |
| 94 | - $event->getIO()->write("[INFO] Saved config to: " . $baseConfigTargetPath); |
|
| 94 | + $event->getIO()->write("[INFO] Saved config to: ".$baseConfigTargetPath); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | private static function copyInstallFile(Event $event, $sourceFileName, $destinationPath, $destinationFileName = null) |
| 98 | 98 | { |
| 99 | - $sourceFilePath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install/_' . $sourceFileName); |
|
| 99 | + $sourceFilePath = realpath(__DIR__.DIRECTORY_SEPARATOR.'install/_'.$sourceFileName); |
|
| 100 | 100 | |
| 101 | 101 | |
| 102 | 102 | if ($destinationFileName === null) { |
@@ -104,15 +104,15 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | if (file_exists($sourceFilePath) && realpath($destinationPath) !== false) { |
| 107 | - $destinationFullPath = realpath($destinationPath) . DIRECTORY_SEPARATOR . $destinationFileName; |
|
| 107 | + $destinationFullPath = realpath($destinationPath).DIRECTORY_SEPARATOR.$destinationFileName; |
|
| 108 | 108 | if (file_exists($destinationFullPath)) { |
| 109 | - $event->getIO()->write("[INFO] File already exists: " . $destinationFullPath); |
|
| 109 | + $event->getIO()->write("[INFO] File already exists: ".$destinationFullPath); |
|
| 110 | 110 | } else { |
| 111 | 111 | copy($sourceFilePath, $destinationFullPath); |
| 112 | - $event->getIO()->write("[INSTALL] Copied file: " . $sourceFileName . ' to ' . $destinationPath); |
|
| 112 | + $event->getIO()->write("[INSTALL] Copied file: ".$sourceFileName.' to '.$destinationPath); |
|
| 113 | 113 | } |
| 114 | 114 | } else { |
| 115 | - $event->getIO()->write("[ERROR] Couldnt copy file: " . $sourceFileName . ' to ' . $destinationPath); |
|
| 115 | + $event->getIO()->write("[ERROR] Couldnt copy file: ".$sourceFileName.' to '.$destinationPath); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | private static function createDir(Event $event, $rootDir, $dirName) |
| 131 | 131 | { |
| 132 | - $dir = $rootDir . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR; |
|
| 132 | + $dir = $rootDir.DIRECTORY_SEPARATOR.$dirName.DIRECTORY_SEPARATOR; |
|
| 133 | 133 | if (!is_dir($dir)) { |
| 134 | 134 | mkdir($dir); |
| 135 | - $event->getIO()->write("[INSTALL] Created dir: " . $dir); |
|
| 135 | + $event->getIO()->write("[INSTALL] Created dir: ".$dir); |
|
| 136 | 136 | } else { |
| 137 | - $event->getIO()->write("[INFO] Dir already exists: " . $dir); |
|
| 137 | + $event->getIO()->write("[INFO] Dir already exists: ".$dir); |
|
| 138 | 138 | } |
| 139 | 139 | return \getRelativePath($rootDir, $dir); |
| 140 | 140 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | private static function getConfig(Event $event, $configTargetPath) |
| 147 | 147 | { |
| 148 | - $baseConfigDefaultPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_config.json'); |
|
| 148 | + $baseConfigDefaultPath = realpath(__DIR__.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'_config.json'); |
|
| 149 | 149 | |
| 150 | 150 | if (file_exists($configTargetPath)) { |
| 151 | 151 | $config = json_decode(file_get_contents($configTargetPath)); |
@@ -24,210 +24,210 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | class Repository |
| 26 | 26 | { |
| 27 | - protected $storagePath; |
|
| 28 | - |
|
| 29 | - protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists', 'redirects'); |
|
| 30 | - |
|
| 31 | - protected $sitemap; |
|
| 32 | - protected $sitemapChanges = false; |
|
| 33 | - |
|
| 34 | - protected $applicationComponents; |
|
| 35 | - protected $applicationComponentsChanges = false; |
|
| 36 | - |
|
| 37 | - protected $documentTypes; |
|
| 38 | - protected $documentTypesChanges = false; |
|
| 39 | - |
|
| 40 | - protected $bricks; |
|
| 41 | - protected $bricksChanges = false; |
|
| 42 | - |
|
| 43 | - protected $imageSet; |
|
| 44 | - protected $imageSetChanges = false; |
|
| 45 | - |
|
| 46 | - protected $images; |
|
| 47 | - protected $imagesChanges = false; |
|
| 48 | - |
|
| 49 | - protected $files; |
|
| 50 | - protected $filesChanges = false; |
|
| 51 | - |
|
| 52 | - protected $users; |
|
| 53 | - protected $usersChanges = false; |
|
| 54 | - |
|
| 55 | - protected $valuelists; |
|
| 56 | - protected $valuelistsChanges = false; |
|
| 57 | - |
|
| 58 | - protected $redirects; |
|
| 59 | - protected $redirectsChanges = false; |
|
| 60 | - |
|
| 61 | - protected $contentDbHandle; |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Repository constructor. |
|
| 66 | - * @param $storagePath |
|
| 67 | - * @throws \Exception |
|
| 68 | - */ |
|
| 69 | - public function __construct($storagePath) |
|
| 70 | - { |
|
| 71 | - $storagePath = realpath($storagePath); |
|
| 72 | - if (is_dir($storagePath) && $storagePath !== false) { |
|
| 73 | - $this->storagePath = $storagePath; |
|
| 74 | - } else { |
|
| 75 | - throw new \Exception('Repository not yet initialized.'); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Creates the folder in which to create all storage related files |
|
| 81 | - * |
|
| 82 | - * @param $storagePath |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - public static function create($storagePath) |
|
| 86 | - { |
|
| 87 | - return mkdir($storagePath); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Initiates default storage |
|
| 92 | - * @param $baseStorageDefaultPath |
|
| 93 | - * @param $baseStorageSqlPath |
|
| 94 | - */ |
|
| 95 | - public function init($baseStorageDefaultPath, $baseStorageSqlPath) |
|
| 96 | - { |
|
| 97 | - $storageDefaultPath = realpath($baseStorageDefaultPath); |
|
| 98 | - $contentSqlPath = realpath($baseStorageSqlPath); |
|
| 99 | - |
|
| 100 | - $this->initConfigStorage($storageDefaultPath); |
|
| 101 | - $this->initContentDb($contentSqlPath); |
|
| 102 | - |
|
| 103 | - $this->save(); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Load filebased subset and return it's contents |
|
| 108 | - * |
|
| 109 | - * @param $name |
|
| 110 | - * @return mixed|string |
|
| 111 | - * @throws \Exception |
|
| 112 | - */ |
|
| 113 | - public function __get($name) |
|
| 114 | - { |
|
| 115 | - if (isset($this->$name)) { |
|
| 116 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 117 | - return $this->$name; |
|
| 118 | - } else { |
|
| 119 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 120 | - } |
|
| 121 | - } else { |
|
| 122 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 123 | - return $this->loadSubset($name); |
|
| 124 | - } else { |
|
| 125 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Set filebased subset contents |
|
| 132 | - * @param $name |
|
| 133 | - * @param $value |
|
| 134 | - * @throws \Exception |
|
| 135 | - */ |
|
| 136 | - public function __set($name, $value) |
|
| 137 | - { |
|
| 138 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 139 | - $this->$name = $value; |
|
| 140 | - $changes = $name . 'Changes'; |
|
| 141 | - $this->$changes = true; |
|
| 142 | - } else { |
|
| 143 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Persist all subsets |
|
| 149 | - */ |
|
| 150 | - public function save() |
|
| 151 | - { |
|
| 152 | - $host = $this; |
|
| 153 | - array_map(function ($value) use ($host) { |
|
| 154 | - $host->saveSubset($value); |
|
| 27 | + protected $storagePath; |
|
| 28 | + |
|
| 29 | + protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists', 'redirects'); |
|
| 30 | + |
|
| 31 | + protected $sitemap; |
|
| 32 | + protected $sitemapChanges = false; |
|
| 33 | + |
|
| 34 | + protected $applicationComponents; |
|
| 35 | + protected $applicationComponentsChanges = false; |
|
| 36 | + |
|
| 37 | + protected $documentTypes; |
|
| 38 | + protected $documentTypesChanges = false; |
|
| 39 | + |
|
| 40 | + protected $bricks; |
|
| 41 | + protected $bricksChanges = false; |
|
| 42 | + |
|
| 43 | + protected $imageSet; |
|
| 44 | + protected $imageSetChanges = false; |
|
| 45 | + |
|
| 46 | + protected $images; |
|
| 47 | + protected $imagesChanges = false; |
|
| 48 | + |
|
| 49 | + protected $files; |
|
| 50 | + protected $filesChanges = false; |
|
| 51 | + |
|
| 52 | + protected $users; |
|
| 53 | + protected $usersChanges = false; |
|
| 54 | + |
|
| 55 | + protected $valuelists; |
|
| 56 | + protected $valuelistsChanges = false; |
|
| 57 | + |
|
| 58 | + protected $redirects; |
|
| 59 | + protected $redirectsChanges = false; |
|
| 60 | + |
|
| 61 | + protected $contentDbHandle; |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Repository constructor. |
|
| 66 | + * @param $storagePath |
|
| 67 | + * @throws \Exception |
|
| 68 | + */ |
|
| 69 | + public function __construct($storagePath) |
|
| 70 | + { |
|
| 71 | + $storagePath = realpath($storagePath); |
|
| 72 | + if (is_dir($storagePath) && $storagePath !== false) { |
|
| 73 | + $this->storagePath = $storagePath; |
|
| 74 | + } else { |
|
| 75 | + throw new \Exception('Repository not yet initialized.'); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Creates the folder in which to create all storage related files |
|
| 81 | + * |
|
| 82 | + * @param $storagePath |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + public static function create($storagePath) |
|
| 86 | + { |
|
| 87 | + return mkdir($storagePath); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Initiates default storage |
|
| 92 | + * @param $baseStorageDefaultPath |
|
| 93 | + * @param $baseStorageSqlPath |
|
| 94 | + */ |
|
| 95 | + public function init($baseStorageDefaultPath, $baseStorageSqlPath) |
|
| 96 | + { |
|
| 97 | + $storageDefaultPath = realpath($baseStorageDefaultPath); |
|
| 98 | + $contentSqlPath = realpath($baseStorageSqlPath); |
|
| 99 | + |
|
| 100 | + $this->initConfigStorage($storageDefaultPath); |
|
| 101 | + $this->initContentDb($contentSqlPath); |
|
| 102 | + |
|
| 103 | + $this->save(); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Load filebased subset and return it's contents |
|
| 108 | + * |
|
| 109 | + * @param $name |
|
| 110 | + * @return mixed|string |
|
| 111 | + * @throws \Exception |
|
| 112 | + */ |
|
| 113 | + public function __get($name) |
|
| 114 | + { |
|
| 115 | + if (isset($this->$name)) { |
|
| 116 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 117 | + return $this->$name; |
|
| 118 | + } else { |
|
| 119 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 123 | + return $this->loadSubset($name); |
|
| 124 | + } else { |
|
| 125 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Set filebased subset contents |
|
| 132 | + * @param $name |
|
| 133 | + * @param $value |
|
| 134 | + * @throws \Exception |
|
| 135 | + */ |
|
| 136 | + public function __set($name, $value) |
|
| 137 | + { |
|
| 138 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 139 | + $this->$name = $value; |
|
| 140 | + $changes = $name . 'Changes'; |
|
| 141 | + $this->$changes = true; |
|
| 142 | + } else { |
|
| 143 | + throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Persist all subsets |
|
| 149 | + */ |
|
| 150 | + public function save() |
|
| 151 | + { |
|
| 152 | + $host = $this; |
|
| 153 | + array_map(function ($value) use ($host) { |
|
| 154 | + $host->saveSubset($value); |
|
| 155 | 155 | }, $this->fileBasedSubsets); |
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Persist subset to disk |
|
| 160 | - * @param $subset |
|
| 161 | - */ |
|
| 162 | - public function saveSubset($subset) |
|
| 163 | - { |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Persist subset to disk |
|
| 160 | + * @param $subset |
|
| 161 | + */ |
|
| 162 | + public function saveSubset($subset) |
|
| 163 | + { |
|
| 164 | 164 | $changes = $subset . 'Changes'; |
| 165 | 165 | if ($this->$changes === true) { |
| 166 | - if (!defined('JSON_PRETTY_PRINT')) { |
|
| 167 | - $json = json_encode($this->$subset); |
|
| 168 | - } else { |
|
| 169 | - $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
|
| 170 | - } |
|
| 166 | + if (!defined('JSON_PRETTY_PRINT')) { |
|
| 167 | + $json = json_encode($this->$subset); |
|
| 168 | + } else { |
|
| 169 | + $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
|
| 170 | + } |
|
| 171 | 171 | $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
| 172 | 172 | file_put_contents($subsetStoragePath, $json); |
| 173 | 173 | |
| 174 | 174 | $this->$changes = false; |
| 175 | 175 | } |
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Load subset from disk |
|
| 180 | - * @param $subset |
|
| 181 | - * @return mixed|string |
|
| 182 | - */ |
|
| 183 | - protected function loadSubset($subset) |
|
| 184 | - { |
|
| 185 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 186 | - $json = file_get_contents($subsetStoragePath); |
|
| 187 | - $json = json_decode($json); |
|
| 188 | - $this->$subset = $json; |
|
| 189 | - return $json; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * @param $contentSqlPath |
|
| 194 | - */ |
|
| 195 | - protected function initContentDb($contentSqlPath) |
|
| 196 | - { |
|
| 197 | - $db = $this->getContentDbHandle(); |
|
| 198 | - $sql = file_get_contents($contentSqlPath); |
|
| 199 | - $db->exec($sql); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @param $storageDefaultPath |
|
| 204 | - */ |
|
| 205 | - protected function initConfigStorage($storageDefaultPath) |
|
| 206 | - { |
|
| 207 | - $json = file_get_contents($storageDefaultPath); |
|
| 208 | - $json = json_decode($json); |
|
| 209 | - $this->initConfigIfNotExists($json, 'sitemap'); |
|
| 210 | - $this->initConfigIfNotExists($json, 'applicationComponents'); |
|
| 211 | - $this->initConfigIfNotExists($json, 'documentTypes'); |
|
| 212 | - $this->initConfigIfNotExists($json, 'bricks'); |
|
| 213 | - $this->initConfigIfNotExists($json, 'imageSet'); |
|
| 214 | - $this->initConfigIfNotExists($json, 'images'); |
|
| 215 | - $this->initConfigIfNotExists($json, 'files'); |
|
| 216 | - $this->initConfigIfNotExists($json, 'users'); |
|
| 217 | - $this->initConfigIfNotExists($json, 'valuelists'); |
|
| 218 | - $this->initConfigIfNotExists($json, 'redirects'); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * @return \PDO |
|
| 223 | - */ |
|
| 224 | - public function getContentDbHandle() |
|
| 225 | - { |
|
| 226 | - if ($this->contentDbHandle === null) { |
|
| 227 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
| 228 | - } |
|
| 229 | - return $this->contentDbHandle; |
|
| 230 | - } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Load subset from disk |
|
| 180 | + * @param $subset |
|
| 181 | + * @return mixed|string |
|
| 182 | + */ |
|
| 183 | + protected function loadSubset($subset) |
|
| 184 | + { |
|
| 185 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 186 | + $json = file_get_contents($subsetStoragePath); |
|
| 187 | + $json = json_decode($json); |
|
| 188 | + $this->$subset = $json; |
|
| 189 | + return $json; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * @param $contentSqlPath |
|
| 194 | + */ |
|
| 195 | + protected function initContentDb($contentSqlPath) |
|
| 196 | + { |
|
| 197 | + $db = $this->getContentDbHandle(); |
|
| 198 | + $sql = file_get_contents($contentSqlPath); |
|
| 199 | + $db->exec($sql); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @param $storageDefaultPath |
|
| 204 | + */ |
|
| 205 | + protected function initConfigStorage($storageDefaultPath) |
|
| 206 | + { |
|
| 207 | + $json = file_get_contents($storageDefaultPath); |
|
| 208 | + $json = json_decode($json); |
|
| 209 | + $this->initConfigIfNotExists($json, 'sitemap'); |
|
| 210 | + $this->initConfigIfNotExists($json, 'applicationComponents'); |
|
| 211 | + $this->initConfigIfNotExists($json, 'documentTypes'); |
|
| 212 | + $this->initConfigIfNotExists($json, 'bricks'); |
|
| 213 | + $this->initConfigIfNotExists($json, 'imageSet'); |
|
| 214 | + $this->initConfigIfNotExists($json, 'images'); |
|
| 215 | + $this->initConfigIfNotExists($json, 'files'); |
|
| 216 | + $this->initConfigIfNotExists($json, 'users'); |
|
| 217 | + $this->initConfigIfNotExists($json, 'valuelists'); |
|
| 218 | + $this->initConfigIfNotExists($json, 'redirects'); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * @return \PDO |
|
| 223 | + */ |
|
| 224 | + public function getContentDbHandle() |
|
| 225 | + { |
|
| 226 | + if ($this->contentDbHandle === null) { |
|
| 227 | + $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
| 228 | + } |
|
| 229 | + return $this->contentDbHandle; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | 232 | /** |
| 233 | 233 | * Get all documents |
@@ -237,13 +237,13 @@ discard block |
||
| 237 | 237 | * @return array |
| 238 | 238 | * @throws \Exception |
| 239 | 239 | */ |
| 240 | - public function getDocuments($state = 'published') |
|
| 241 | - { |
|
| 240 | + public function getDocuments($state = 'published') |
|
| 241 | + { |
|
| 242 | 242 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 243 | 243 | throw new \Exception('Unsupported document state: ' . $state); |
| 244 | 244 | } |
| 245 | - return $this->getDocumentsByPath('/', $state); |
|
| 246 | - } |
|
| 245 | + return $this->getDocumentsByPath('/', $state); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | 248 | public function getDocumentsWithState($folderPath = '/') |
| 249 | 249 | { |
@@ -290,51 +290,51 @@ discard block |
||
| 290 | 290 | * @return array |
| 291 | 291 | * @throws \Exception |
| 292 | 292 | */ |
| 293 | - public function getDocumentsByPath($folderPath, $state = 'published') |
|
| 294 | - { |
|
| 295 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 296 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 293 | + public function getDocumentsByPath($folderPath, $state = 'published') |
|
| 294 | + { |
|
| 295 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
| 296 | + throw new \Exception('Unsupported document state: ' . $state); |
|
| 297 | 297 | } |
| 298 | - $db = $this->getContentDbHandle(); |
|
| 299 | - $folderPathWithWildcard = $folderPath . '%'; |
|
| 298 | + $db = $this->getContentDbHandle(); |
|
| 299 | + $folderPathWithWildcard = $folderPath . '%'; |
|
| 300 | 300 | |
| 301 | - $sql = 'SELECT * |
|
| 301 | + $sql = 'SELECT * |
|
| 302 | 302 | FROM documents_' . $state . ' |
| 303 | 303 | WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
| 304 | 304 | AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
| 305 | 305 | AND path != ' . $db->quote($folderPath) . ' |
| 306 | 306 | ORDER BY `type` DESC, `path` ASC'; |
| 307 | - $stmt = $this->getDbStatement($sql); |
|
| 307 | + $stmt = $this->getDbStatement($sql); |
|
| 308 | 308 | |
| 309 | - $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
| 310 | - foreach ($documents as $key => $document) { |
|
| 309 | + $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
| 310 | + foreach ($documents as $key => $document) { |
|
| 311 | 311 | $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
| 312 | - } |
|
| 313 | - return $documents; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @param $path |
|
| 319 | - * @return bool|Document |
|
| 320 | - */ |
|
| 321 | - public function getDocumentContainerByPath($path) |
|
| 322 | - { |
|
| 323 | - $document = $this->getDocumentByPath($path, 'unpublished'); |
|
| 324 | - if ($document === false) { |
|
| 325 | - return false; |
|
| 326 | - } |
|
| 327 | - $slugLength = strlen($document->slug); |
|
| 328 | - $containerPath = substr($path, 0, -$slugLength); |
|
| 329 | - if ($containerPath === '/') { |
|
| 330 | - return $this->getRootFolder(); |
|
| 331 | - } |
|
| 332 | - if (substr($containerPath, -1) === '/'){ |
|
| 312 | + } |
|
| 313 | + return $documents; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @param $path |
|
| 319 | + * @return bool|Document |
|
| 320 | + */ |
|
| 321 | + public function getDocumentContainerByPath($path) |
|
| 322 | + { |
|
| 323 | + $document = $this->getDocumentByPath($path, 'unpublished'); |
|
| 324 | + if ($document === false) { |
|
| 325 | + return false; |
|
| 326 | + } |
|
| 327 | + $slugLength = strlen($document->slug); |
|
| 328 | + $containerPath = substr($path, 0, -$slugLength); |
|
| 329 | + if ($containerPath === '/') { |
|
| 330 | + return $this->getRootFolder(); |
|
| 331 | + } |
|
| 332 | + if (substr($containerPath, -1) === '/'){ |
|
| 333 | 333 | $containerPath = substr($containerPath, 0, -1); |
| 334 | 334 | } |
| 335 | - $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
|
| 336 | - return $containerFolder; |
|
| 337 | - } |
|
| 335 | + $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
|
| 336 | + return $containerFolder; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | 339 | /** |
| 340 | 340 | * @param $path |
@@ -343,23 +343,23 @@ discard block |
||
| 343 | 343 | * @return bool|\CloudControl\Cms\storage\Document |
| 344 | 344 | * @throws \Exception |
| 345 | 345 | */ |
| 346 | - public function getDocumentByPath($path, $state = 'published') |
|
| 347 | - { |
|
| 346 | + public function getDocumentByPath($path, $state = 'published') |
|
| 347 | + { |
|
| 348 | 348 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 349 | 349 | throw new \Exception('Unsupported document state: ' . $state); |
| 350 | 350 | } |
| 351 | - $db = $this->getContentDbHandle(); |
|
| 352 | - $document = $this->fetchDocument(' |
|
| 351 | + $db = $this->getContentDbHandle(); |
|
| 352 | + $document = $this->fetchDocument(' |
|
| 353 | 353 | SELECT * |
| 354 | 354 | FROM documents_' . $state . ' |
| 355 | 355 | WHERE path = ' . $db->quote($path) . ' |
| 356 | 356 | '); |
| 357 | - if ($document instanceof Document && $document->type === 'folder') { |
|
| 358 | - $document->dbHandle = $db; |
|
| 359 | - $document->documentStorage = new DocumentStorage($this); |
|
| 360 | - } |
|
| 361 | - return $document; |
|
| 362 | - } |
|
| 357 | + if ($document instanceof Document && $document->type === 'folder') { |
|
| 358 | + $document->dbHandle = $db; |
|
| 359 | + $document->documentStorage = new DocumentStorage($this); |
|
| 360 | + } |
|
| 361 | + return $document; |
|
| 362 | + } |
|
| 363 | 363 | |
| 364 | 364 | /** |
| 365 | 365 | * Returns the count of all documents stored in the db |
@@ -454,58 +454,58 @@ discard block |
||
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
| 457 | - * Return the results of the query as array of Documents |
|
| 458 | - * @param $sql |
|
| 459 | - * @return array |
|
| 460 | - * @throws \Exception |
|
| 461 | - */ |
|
| 462 | - protected function fetchAllDocuments($sql) |
|
| 463 | - { |
|
| 464 | - $stmt = $this->getDbStatement($sql); |
|
| 465 | - return $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * Return the result of the query as Document |
|
| 470 | - * @param $sql |
|
| 471 | - * @return mixed |
|
| 472 | - * @throws \Exception |
|
| 473 | - */ |
|
| 474 | - protected function fetchDocument($sql) |
|
| 475 | - { |
|
| 476 | - $stmt = $this->getDbStatement($sql); |
|
| 477 | - return $stmt->fetchObject('\CloudControl\Cms\storage\Document'); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * Prepare the sql statement |
|
| 482 | - * @param $sql |
|
| 483 | - * @return \PDOStatement |
|
| 484 | - * @throws \Exception |
|
| 485 | - */ |
|
| 486 | - protected function getDbStatement($sql) |
|
| 487 | - { |
|
| 488 | - $db = $this->getContentDbHandle(); |
|
| 489 | - $stmt = $db->query($sql); |
|
| 490 | - if ($stmt === false) { |
|
| 491 | - $errorInfo = $db->errorInfo(); |
|
| 492 | - $errorMsg = $errorInfo[2]; |
|
| 493 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 494 | - } |
|
| 495 | - return $stmt; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Create a (non-existent) root folder Document and return it |
|
| 500 | - * @return Document |
|
| 501 | - */ |
|
| 502 | - protected function getRootFolder() |
|
| 503 | - { |
|
| 504 | - $rootFolder = new Document(); |
|
| 505 | - $rootFolder->path = '/'; |
|
| 506 | - $rootFolder->type = 'folder'; |
|
| 507 | - return $rootFolder; |
|
| 508 | - } |
|
| 457 | + * Return the results of the query as array of Documents |
|
| 458 | + * @param $sql |
|
| 459 | + * @return array |
|
| 460 | + * @throws \Exception |
|
| 461 | + */ |
|
| 462 | + protected function fetchAllDocuments($sql) |
|
| 463 | + { |
|
| 464 | + $stmt = $this->getDbStatement($sql); |
|
| 465 | + return $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * Return the result of the query as Document |
|
| 470 | + * @param $sql |
|
| 471 | + * @return mixed |
|
| 472 | + * @throws \Exception |
|
| 473 | + */ |
|
| 474 | + protected function fetchDocument($sql) |
|
| 475 | + { |
|
| 476 | + $stmt = $this->getDbStatement($sql); |
|
| 477 | + return $stmt->fetchObject('\CloudControl\Cms\storage\Document'); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * Prepare the sql statement |
|
| 482 | + * @param $sql |
|
| 483 | + * @return \PDOStatement |
|
| 484 | + * @throws \Exception |
|
| 485 | + */ |
|
| 486 | + protected function getDbStatement($sql) |
|
| 487 | + { |
|
| 488 | + $db = $this->getContentDbHandle(); |
|
| 489 | + $stmt = $db->query($sql); |
|
| 490 | + if ($stmt === false) { |
|
| 491 | + $errorInfo = $db->errorInfo(); |
|
| 492 | + $errorMsg = $errorInfo[2]; |
|
| 493 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 494 | + } |
|
| 495 | + return $stmt; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Create a (non-existent) root folder Document and return it |
|
| 500 | + * @return Document |
|
| 501 | + */ |
|
| 502 | + protected function getRootFolder() |
|
| 503 | + { |
|
| 504 | + $rootFolder = new Document(); |
|
| 505 | + $rootFolder->path = '/'; |
|
| 506 | + $rootFolder->type = 'folder'; |
|
| 507 | + return $rootFolder; |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | 510 | /** |
| 511 | 511 | * Save the document to the database |
@@ -517,13 +517,13 @@ discard block |
||
| 517 | 517 | * @throws \Exception |
| 518 | 518 | * @internal param $path |
| 519 | 519 | */ |
| 520 | - public function saveDocument($documentObject, $state = 'published') |
|
| 521 | - { |
|
| 520 | + public function saveDocument($documentObject, $state = 'published') |
|
| 521 | + { |
|
| 522 | 522 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 523 | 523 | throw new \Exception('Unsupported document state: ' . $state); |
| 524 | 524 | } |
| 525 | - $db = $this->getContentDbHandle(); |
|
| 526 | - $stmt = $this->getDbStatement(' |
|
| 525 | + $db = $this->getContentDbHandle(); |
|
| 526 | + $stmt = $this->getDbStatement(' |
|
| 527 | 527 | INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
| 528 | 528 | VALUES( |
| 529 | 529 | ' . $db->quote($documentObject->path) . ', |
@@ -541,9 +541,9 @@ discard block |
||
| 541 | 541 | ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
| 542 | 542 | ) |
| 543 | 543 | '); |
| 544 | - $result = $stmt->execute(); |
|
| 545 | - return $result; |
|
| 546 | - } |
|
| 544 | + $result = $stmt->execute(); |
|
| 545 | + return $result; |
|
| 546 | + } |
|
| 547 | 547 | |
| 548 | 548 | /** |
| 549 | 549 | * Delete the document from the database |
@@ -554,29 +554,29 @@ discard block |
||
| 554 | 554 | * @internal param string $state |
| 555 | 555 | * |
| 556 | 556 | */ |
| 557 | - public function deleteDocumentByPath($path) |
|
| 558 | - { |
|
| 559 | - $db = $this->getContentDbHandle(); |
|
| 560 | - $documentToDelete = $this->getDocumentByPath($path, 'unpublished'); |
|
| 561 | - if ($documentToDelete instanceof Document) { |
|
| 562 | - if ($documentToDelete->type == 'document') { |
|
| 563 | - $stmt = $this->getDbStatement(' |
|
| 557 | + public function deleteDocumentByPath($path) |
|
| 558 | + { |
|
| 559 | + $db = $this->getContentDbHandle(); |
|
| 560 | + $documentToDelete = $this->getDocumentByPath($path, 'unpublished'); |
|
| 561 | + if ($documentToDelete instanceof Document) { |
|
| 562 | + if ($documentToDelete->type == 'document') { |
|
| 563 | + $stmt = $this->getDbStatement(' |
|
| 564 | 564 | DELETE FROM documents_unpublished |
| 565 | 565 | WHERE path = ' . $db->quote($path) . ' |
| 566 | 566 | '); |
| 567 | - $stmt->execute(); |
|
| 568 | - } elseif ($documentToDelete->type == 'folder') { |
|
| 569 | - $folderPathWithWildcard = $path . '%'; |
|
| 570 | - $stmt = $this->getDbStatement(' |
|
| 567 | + $stmt->execute(); |
|
| 568 | + } elseif ($documentToDelete->type == 'folder') { |
|
| 569 | + $folderPathWithWildcard = $path . '%'; |
|
| 570 | + $stmt = $this->getDbStatement(' |
|
| 571 | 571 | DELETE FROM documents_unpublished |
| 572 | 572 | WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
| 573 | 573 | AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
| 574 | 574 | OR path = ' . $db->quote($path) . ' |
| 575 | 575 | '); |
| 576 | - $stmt->execute(); |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - } |
|
| 576 | + $stmt->execute(); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + } |
|
| 580 | 580 | |
| 581 | 581 | /** |
| 582 | 582 | * @param $document |
@@ -597,15 +597,15 @@ discard block |
||
| 597 | 597 | return $documents; |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | - private function initConfigIfNotExists($json, $subsetName) |
|
| 601 | - { |
|
| 602 | - $subsetFileName = $this->storagePath . DIRECTORY_SEPARATOR . $subsetName . '.json'; |
|
| 603 | - if (file_exists($subsetFileName)) { |
|
| 604 | - $this->loadSubset($subsetName); |
|
| 605 | - } else { |
|
| 606 | - $changes = $subsetName . 'Changes'; |
|
| 607 | - $this->$subsetName = $json->$subsetName; |
|
| 608 | - $this->$changes = true; |
|
| 609 | - } |
|
| 610 | - } |
|
| 600 | + private function initConfigIfNotExists($json, $subsetName) |
|
| 601 | + { |
|
| 602 | + $subsetFileName = $this->storagePath . DIRECTORY_SEPARATOR . $subsetName . '.json'; |
|
| 603 | + if (file_exists($subsetFileName)) { |
|
| 604 | + $this->loadSubset($subsetName); |
|
| 605 | + } else { |
|
| 606 | + $changes = $subsetName . 'Changes'; |
|
| 607 | + $this->$subsetName = $json->$subsetName; |
|
| 608 | + $this->$changes = true; |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | 611 | } |
| 612 | 612 | \ No newline at end of file |
@@ -116,13 +116,13 @@ discard block |
||
| 116 | 116 | if (in_array($name, $this->fileBasedSubsets)) { |
| 117 | 117 | return $this->$name; |
| 118 | 118 | } else { |
| 119 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 119 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
| 120 | 120 | } |
| 121 | 121 | } else { |
| 122 | 122 | if (in_array($name, $this->fileBasedSubsets)) { |
| 123 | 123 | return $this->loadSubset($name); |
| 124 | 124 | } else { |
| 125 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 125 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | { |
| 138 | 138 | if (in_array($name, $this->fileBasedSubsets)) { |
| 139 | 139 | $this->$name = $value; |
| 140 | - $changes = $name . 'Changes'; |
|
| 140 | + $changes = $name.'Changes'; |
|
| 141 | 141 | $this->$changes = true; |
| 142 | 142 | } else { |
| 143 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 143 | + throw new \Exception('Trying to persist unknown subset in repository: '.$name.' <br /><pre>'.print_r($value, true).'</pre>'); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | public function save() |
| 151 | 151 | { |
| 152 | 152 | $host = $this; |
| 153 | - array_map(function ($value) use ($host) { |
|
| 153 | + array_map(function($value) use ($host) { |
|
| 154 | 154 | $host->saveSubset($value); |
| 155 | 155 | }, $this->fileBasedSubsets); |
| 156 | 156 | } |
@@ -161,14 +161,14 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function saveSubset($subset) |
| 163 | 163 | { |
| 164 | - $changes = $subset . 'Changes'; |
|
| 164 | + $changes = $subset.'Changes'; |
|
| 165 | 165 | if ($this->$changes === true) { |
| 166 | 166 | if (!defined('JSON_PRETTY_PRINT')) { |
| 167 | 167 | $json = json_encode($this->$subset); |
| 168 | 168 | } else { |
| 169 | 169 | $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
| 170 | 170 | } |
| 171 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 171 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
| 172 | 172 | file_put_contents($subsetStoragePath, $json); |
| 173 | 173 | |
| 174 | 174 | $this->$changes = false; |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | protected function loadSubset($subset) |
| 184 | 184 | { |
| 185 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 185 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
| 186 | 186 | $json = file_get_contents($subsetStoragePath); |
| 187 | 187 | $json = json_decode($json); |
| 188 | 188 | $this->$subset = $json; |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | public function getContentDbHandle() |
| 225 | 225 | { |
| 226 | 226 | if ($this->contentDbHandle === null) { |
| 227 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
| 227 | + $this->contentDbHandle = new \PDO('sqlite:'.$this->storagePath.DIRECTORY_SEPARATOR.'content.db'); |
|
| 228 | 228 | } |
| 229 | 229 | return $this->contentDbHandle; |
| 230 | 230 | } |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | public function getDocuments($state = 'published') |
| 241 | 241 | { |
| 242 | 242 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 243 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 243 | + throw new \Exception('Unsupported document state: '.$state); |
|
| 244 | 244 | } |
| 245 | 245 | return $this->getDocumentsByPath('/', $state); |
| 246 | 246 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | public function getDocumentsWithState($folderPath = '/') |
| 249 | 249 | { |
| 250 | 250 | $db = $this->getContentDbHandle(); |
| 251 | - $folderPathWithWildcard = $folderPath . '%'; |
|
| 251 | + $folderPathWithWildcard = $folderPath.'%'; |
|
| 252 | 252 | |
| 253 | 253 | $ifRootIndex = 1; |
| 254 | 254 | if ($folderPath == '/') { |
@@ -263,10 +263,10 @@ discard block |
||
| 263 | 263 | FROM documents_unpublished |
| 264 | 264 | LEFT JOIN documents_published |
| 265 | 265 | ON documents_published.path = documents_unpublished.path |
| 266 | - WHERE documents_unpublished.`path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
| 267 | - AND substr(documents_unpublished.`path`, ' . (strlen($folderPath) + $ifRootIndex + 1) . ') NOT LIKE "%/%" |
|
| 268 | - AND length(documents_unpublished.`path`) > ' . (strlen($folderPath) + $ifRootIndex) . ' |
|
| 269 | - AND documents_unpublished.path != ' . $db->quote($folderPath) . ' |
|
| 266 | + WHERE documents_unpublished.`path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
| 267 | + AND substr(documents_unpublished.`path`, ' . (strlen($folderPath) + $ifRootIndex + 1).') NOT LIKE "%/%" |
|
| 268 | + AND length(documents_unpublished.`path`) > ' . (strlen($folderPath) + $ifRootIndex).' |
|
| 269 | + AND documents_unpublished.path != ' . $db->quote($folderPath).' |
|
| 270 | 270 | ORDER BY documents_unpublished.`type` DESC, documents_unpublished.`path` ASC |
| 271 | 271 | '; |
| 272 | 272 | $stmt = $this->getDbStatement($sql); |
@@ -293,16 +293,16 @@ discard block |
||
| 293 | 293 | public function getDocumentsByPath($folderPath, $state = 'published') |
| 294 | 294 | { |
| 295 | 295 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 296 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 296 | + throw new \Exception('Unsupported document state: '.$state); |
|
| 297 | 297 | } |
| 298 | 298 | $db = $this->getContentDbHandle(); |
| 299 | - $folderPathWithWildcard = $folderPath . '%'; |
|
| 299 | + $folderPathWithWildcard = $folderPath.'%'; |
|
| 300 | 300 | |
| 301 | 301 | $sql = 'SELECT * |
| 302 | - FROM documents_' . $state . ' |
|
| 303 | - WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
| 304 | - AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
|
| 305 | - AND path != ' . $db->quote($folderPath) . ' |
|
| 302 | + FROM documents_' . $state.' |
|
| 303 | + WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
| 304 | + AND substr(`path`, ' . (strlen($folderPath) + 1).') NOT LIKE "%/%" |
|
| 305 | + AND path != ' . $db->quote($folderPath).' |
|
| 306 | 306 | ORDER BY `type` DESC, `path` ASC'; |
| 307 | 307 | $stmt = $this->getDbStatement($sql); |
| 308 | 308 | |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | if ($containerPath === '/') { |
| 330 | 330 | return $this->getRootFolder(); |
| 331 | 331 | } |
| 332 | - if (substr($containerPath, -1) === '/'){ |
|
| 332 | + if (substr($containerPath, -1) === '/') { |
|
| 333 | 333 | $containerPath = substr($containerPath, 0, -1); |
| 334 | 334 | } |
| 335 | 335 | $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
@@ -346,13 +346,13 @@ discard block |
||
| 346 | 346 | public function getDocumentByPath($path, $state = 'published') |
| 347 | 347 | { |
| 348 | 348 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 349 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 349 | + throw new \Exception('Unsupported document state: '.$state); |
|
| 350 | 350 | } |
| 351 | 351 | $db = $this->getContentDbHandle(); |
| 352 | 352 | $document = $this->fetchDocument(' |
| 353 | 353 | SELECT * |
| 354 | - FROM documents_' . $state . ' |
|
| 355 | - WHERE path = ' . $db->quote($path) . ' |
|
| 354 | + FROM documents_' . $state.' |
|
| 355 | + WHERE path = ' . $db->quote($path).' |
|
| 356 | 356 | '); |
| 357 | 357 | if ($document instanceof Document && $document->type === 'folder') { |
| 358 | 358 | $document->dbHandle = $db; |
@@ -372,16 +372,16 @@ discard block |
||
| 372 | 372 | public function getTotalDocumentCount($state = 'published') |
| 373 | 373 | { |
| 374 | 374 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 375 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 375 | + throw new \Exception('Unsupported document state: '.$state); |
|
| 376 | 376 | } |
| 377 | 377 | $db = $this->getContentDbHandle(); |
| 378 | 378 | $stmt = $db->query(' |
| 379 | 379 | SELECT count(*) |
| 380 | - FROM documents_' . $state . ' |
|
| 380 | + FROM documents_' . $state.' |
|
| 381 | 381 | WHERE `type` != "folder" |
| 382 | 382 | '); |
| 383 | 383 | $result = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 384 | - if (!is_array($result )) { |
|
| 384 | + if (!is_array($result)) { |
|
| 385 | 385 | return 0; |
| 386 | 386 | } |
| 387 | 387 | return intval(current($result)); |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | if ($stmt === false || !$stmt->execute()) { |
| 401 | 401 | $errorInfo = $db->errorInfo(); |
| 402 | 402 | $errorMsg = $errorInfo[2]; |
| 403 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 403 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
| 404 | 404 | } |
| 405 | 405 | return $result; |
| 406 | 406 | } |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | $sql = ' |
| 411 | 411 | INSERT OR REPLACE INTO documents_published |
| 412 | 412 | (`id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`publicationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
| 413 | - SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time() . ' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks` |
|
| 413 | + SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time().' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks` |
|
| 414 | 414 | FROM documents_unpublished |
| 415 | 415 | WHERE `path` = :path |
| 416 | 416 | '; |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | if ($stmt === false) { |
| 424 | 424 | $errorInfo = $db->errorInfo(); |
| 425 | 425 | $errorMsg = $errorInfo[2]; |
| 426 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 426 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
| 427 | 427 | } |
| 428 | 428 | $stmt->bindValue(':path', $path); |
| 429 | 429 | $stmt->execute(); |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | if ($stmt === false) { |
| 491 | 491 | $errorInfo = $db->errorInfo(); |
| 492 | 492 | $errorMsg = $errorInfo[2]; |
| 493 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 493 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
| 494 | 494 | } |
| 495 | 495 | return $stmt; |
| 496 | 496 | } |
@@ -520,25 +520,25 @@ discard block |
||
| 520 | 520 | public function saveDocument($documentObject, $state = 'published') |
| 521 | 521 | { |
| 522 | 522 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
| 523 | - throw new \Exception('Unsupported document state: ' . $state); |
|
| 523 | + throw new \Exception('Unsupported document state: '.$state); |
|
| 524 | 524 | } |
| 525 | 525 | $db = $this->getContentDbHandle(); |
| 526 | 526 | $stmt = $this->getDbStatement(' |
| 527 | - INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
|
| 527 | + INSERT OR REPLACE INTO documents_' . $state.' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
|
| 528 | 528 | VALUES( |
| 529 | - ' . $db->quote($documentObject->path) . ', |
|
| 530 | - ' . $db->quote($documentObject->title) . ', |
|
| 531 | - ' . $db->quote($documentObject->slug) . ', |
|
| 532 | - ' . $db->quote($documentObject->type) . ', |
|
| 533 | - ' . $db->quote($documentObject->documentType) . ', |
|
| 534 | - ' . $db->quote($documentObject->documentTypeSlug) . ', |
|
| 535 | - ' . $db->quote($documentObject->state) . ', |
|
| 536 | - ' . $db->quote($documentObject->lastModificationDate) . ', |
|
| 537 | - ' . $db->quote($documentObject->creationDate) . ', |
|
| 538 | - ' . $db->quote($documentObject->lastModifiedBy) . ', |
|
| 539 | - ' . $db->quote(json_encode($documentObject->fields)) . ', |
|
| 540 | - ' . $db->quote(json_encode($documentObject->bricks)) . ', |
|
| 541 | - ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
|
| 529 | + ' . $db->quote($documentObject->path).', |
|
| 530 | + ' . $db->quote($documentObject->title).', |
|
| 531 | + ' . $db->quote($documentObject->slug).', |
|
| 532 | + ' . $db->quote($documentObject->type).', |
|
| 533 | + ' . $db->quote($documentObject->documentType).', |
|
| 534 | + ' . $db->quote($documentObject->documentTypeSlug).', |
|
| 535 | + ' . $db->quote($documentObject->state).', |
|
| 536 | + ' . $db->quote($documentObject->lastModificationDate).', |
|
| 537 | + ' . $db->quote($documentObject->creationDate).', |
|
| 538 | + ' . $db->quote($documentObject->lastModifiedBy).', |
|
| 539 | + ' . $db->quote(json_encode($documentObject->fields)).', |
|
| 540 | + ' . $db->quote(json_encode($documentObject->bricks)).', |
|
| 541 | + ' . $db->quote(json_encode($documentObject->dynamicBricks)).' |
|
| 542 | 542 | ) |
| 543 | 543 | '); |
| 544 | 544 | $result = $stmt->execute(); |
@@ -562,16 +562,16 @@ discard block |
||
| 562 | 562 | if ($documentToDelete->type == 'document') { |
| 563 | 563 | $stmt = $this->getDbStatement(' |
| 564 | 564 | DELETE FROM documents_unpublished |
| 565 | - WHERE path = ' . $db->quote($path) . ' |
|
| 565 | + WHERE path = ' . $db->quote($path).' |
|
| 566 | 566 | '); |
| 567 | 567 | $stmt->execute(); |
| 568 | 568 | } elseif ($documentToDelete->type == 'folder') { |
| 569 | - $folderPathWithWildcard = $path . '%'; |
|
| 569 | + $folderPathWithWildcard = $path.'%'; |
|
| 570 | 570 | $stmt = $this->getDbStatement(' |
| 571 | 571 | DELETE FROM documents_unpublished |
| 572 | - WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
| 573 | - AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
|
| 574 | - OR path = ' . $db->quote($path) . ' |
|
| 572 | + WHERE (path LIKE ' . $db->quote($folderPathWithWildcard).' |
|
| 573 | + AND substr(`path`, ' . (strlen($path) + 1).', 1) = "/") |
|
| 574 | + OR path = ' . $db->quote($path).' |
|
| 575 | 575 | '); |
| 576 | 576 | $stmt->execute(); |
| 577 | 577 | } |
@@ -599,11 +599,11 @@ discard block |
||
| 599 | 599 | |
| 600 | 600 | private function initConfigIfNotExists($json, $subsetName) |
| 601 | 601 | { |
| 602 | - $subsetFileName = $this->storagePath . DIRECTORY_SEPARATOR . $subsetName . '.json'; |
|
| 602 | + $subsetFileName = $this->storagePath.DIRECTORY_SEPARATOR.$subsetName.'.json'; |
|
| 603 | 603 | if (file_exists($subsetFileName)) { |
| 604 | 604 | $this->loadSubset($subsetName); |
| 605 | 605 | } else { |
| 606 | - $changes = $subsetName . 'Changes'; |
|
| 606 | + $changes = $subsetName.'Changes'; |
|
| 607 | 607 | $this->$subsetName = $json->$subsetName; |
| 608 | 608 | $this->$changes = true; |
| 609 | 609 | } |
@@ -10,94 +10,94 @@ |
||
| 10 | 10 | |
| 11 | 11 | class RedirectsStorage extends AbstractStorage |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Get all redirects |
|
| 15 | - * |
|
| 16 | - * @return mixed |
|
| 17 | - */ |
|
| 18 | - public function getRedirects() |
|
| 19 | - { |
|
| 20 | - $redirects = $this->repository->redirects; |
|
| 21 | - if ($redirects === null) { |
|
| 22 | - $redirects = array(); |
|
| 23 | - } |
|
| 24 | - usort($redirects, array($this, 'cmp')); |
|
| 25 | - return $redirects; |
|
| 26 | - } |
|
| 13 | + /** |
|
| 14 | + * Get all redirects |
|
| 15 | + * |
|
| 16 | + * @return mixed |
|
| 17 | + */ |
|
| 18 | + public function getRedirects() |
|
| 19 | + { |
|
| 20 | + $redirects = $this->repository->redirects; |
|
| 21 | + if ($redirects === null) { |
|
| 22 | + $redirects = array(); |
|
| 23 | + } |
|
| 24 | + usort($redirects, array($this, 'cmp')); |
|
| 25 | + return $redirects; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Add a new redirect |
|
| 30 | - * @param $postValues |
|
| 31 | - */ |
|
| 32 | - public function addRedirect($postValues) { |
|
| 33 | - $redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues); |
|
| 34 | - $redirects = $this->repository->redirects; |
|
| 35 | - $redirects[] = $redirectObject; |
|
| 36 | - $this->repository->redirects = $redirects; |
|
| 37 | - $this->save(); |
|
| 38 | - } |
|
| 28 | + /** |
|
| 29 | + * Add a new redirect |
|
| 30 | + * @param $postValues |
|
| 31 | + */ |
|
| 32 | + public function addRedirect($postValues) { |
|
| 33 | + $redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues); |
|
| 34 | + $redirects = $this->repository->redirects; |
|
| 35 | + $redirects[] = $redirectObject; |
|
| 36 | + $this->repository->redirects = $redirects; |
|
| 37 | + $this->save(); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Get a redirect by it's slug |
|
| 42 | - * |
|
| 43 | - * @param $slug |
|
| 44 | - * @return \stdClass|null |
|
| 45 | - */ |
|
| 46 | - public function getRedirectBySlug($slug) |
|
| 47 | - { |
|
| 48 | - $redirects = $this->repository->redirects; |
|
| 49 | - foreach ($redirects as $redirect) { |
|
| 50 | - if ($redirect->slug == $slug) { |
|
| 51 | - return $redirect; |
|
| 52 | - } |
|
| 53 | - } |
|
| 40 | + /** |
|
| 41 | + * Get a redirect by it's slug |
|
| 42 | + * |
|
| 43 | + * @param $slug |
|
| 44 | + * @return \stdClass|null |
|
| 45 | + */ |
|
| 46 | + public function getRedirectBySlug($slug) |
|
| 47 | + { |
|
| 48 | + $redirects = $this->repository->redirects; |
|
| 49 | + foreach ($redirects as $redirect) { |
|
| 50 | + if ($redirect->slug == $slug) { |
|
| 51 | + return $redirect; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - return null; |
|
| 56 | - } |
|
| 55 | + return null; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Save a redirect by it's slug |
|
| 60 | - * @param $slug |
|
| 61 | - * @param $postValues |
|
| 62 | - */ |
|
| 63 | - public function saveRedirect($slug, $postValues) |
|
| 64 | - { |
|
| 65 | - $redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues); |
|
| 58 | + /** |
|
| 59 | + * Save a redirect by it's slug |
|
| 60 | + * @param $slug |
|
| 61 | + * @param $postValues |
|
| 62 | + */ |
|
| 63 | + public function saveRedirect($slug, $postValues) |
|
| 64 | + { |
|
| 65 | + $redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues); |
|
| 66 | 66 | |
| 67 | - $redirects = $this->repository->redirects; |
|
| 68 | - foreach ($redirects as $key => $redirect) { |
|
| 69 | - if ($redirect->slug == $slug) { |
|
| 70 | - $redirects[$key] = $redirectObject; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - $this->repository->redirects = $redirects; |
|
| 74 | - $this->save(); |
|
| 75 | - } |
|
| 67 | + $redirects = $this->repository->redirects; |
|
| 68 | + foreach ($redirects as $key => $redirect) { |
|
| 69 | + if ($redirect->slug == $slug) { |
|
| 70 | + $redirects[$key] = $redirectObject; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + $this->repository->redirects = $redirects; |
|
| 74 | + $this->save(); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Delete a redirect by it's slug |
|
| 79 | - * @param $slug |
|
| 80 | - */ |
|
| 81 | - public function deleteRedirectBySlug($slug) |
|
| 82 | - { |
|
| 83 | - $redirects = $this->repository->redirects; |
|
| 84 | - foreach ($redirects as $key => $redirect) { |
|
| 85 | - if ($redirect->slug == $slug) { |
|
| 86 | - unset($redirects[$key]); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - $redirects = array_values($redirects); |
|
| 90 | - $this->repository->redirects = $redirects; |
|
| 91 | - $this->save(); |
|
| 92 | - } |
|
| 77 | + /** |
|
| 78 | + * Delete a redirect by it's slug |
|
| 79 | + * @param $slug |
|
| 80 | + */ |
|
| 81 | + public function deleteRedirectBySlug($slug) |
|
| 82 | + { |
|
| 83 | + $redirects = $this->repository->redirects; |
|
| 84 | + foreach ($redirects as $key => $redirect) { |
|
| 85 | + if ($redirect->slug == $slug) { |
|
| 86 | + unset($redirects[$key]); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + $redirects = array_values($redirects); |
|
| 90 | + $this->repository->redirects = $redirects; |
|
| 91 | + $this->save(); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Compare a redirect by it's title |
|
| 96 | - * @param $a |
|
| 97 | - * @param $b |
|
| 98 | - * @return int |
|
| 99 | - */ |
|
| 100 | - public static function cmp($a, $b) { |
|
| 101 | - return strcmp($a->title, $b->title); |
|
| 102 | - } |
|
| 94 | + /** |
|
| 95 | + * Compare a redirect by it's title |
|
| 96 | + * @param $a |
|
| 97 | + * @param $b |
|
| 98 | + * @return int |
|
| 99 | + */ |
|
| 100 | + public static function cmp($a, $b) { |
|
| 101 | + return strcmp($a->title, $b->title); |
|
| 102 | + } |
|
| 103 | 103 | } |
| 104 | 104 | \ No newline at end of file |