@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | $lang['auth.password_strength'] = 'Password Strength'; |
| 28 | 28 | $lang['auth.pass_not_strong'] = 'The Password must be stronger.'; |
| 29 | 29 | |
| 30 | -$lang['auth.have_account'] = 'Already a member? <a href="'. site_url( \Myth\Route::named('login') ) .'">Sign In</a>'; |
|
| 31 | -$lang['auth.need_account'] = 'Need an Account? <a href="'. site_url( \Myth\Route::named('register') ) .'">Sign Up</a>'; |
|
| 32 | -$lang['auth.forgot_pass'] = '<a href="'. site_url( \Myth\Route::named('forgot_pass') ) .'">Forgot your Password?</a>'; |
|
| 30 | +$lang['auth.have_account'] = 'Already a member? <a href="'.site_url(\Myth\Route::named('login')).'">Sign In</a>'; |
|
| 31 | +$lang['auth.need_account'] = 'Need an Account? <a href="'.site_url(\Myth\Route::named('register')).'">Sign Up</a>'; |
|
| 32 | +$lang['auth.forgot_pass'] = '<a href="'.site_url(\Myth\Route::named('forgot_pass')).'">Forgot your Password?</a>'; |
|
| 33 | 33 | |
| 34 | 34 | $lang['auth.first_name'] = 'First Name'; |
| 35 | 35 | $lang['auth.last_name'] = 'Last Name'; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $lang['auth.activate'] = 'Activate'; |
| 57 | 57 | $lang['auth.inactive_account'] = 'Your account is not active.'; |
| 58 | 58 | |
| 59 | -$lang['auth.register_subject'] = "Open to activate your account at ". config_item('site.name'); |
|
| 59 | +$lang['auth.register_subject'] = "Open to activate your account at ".config_item('site.name'); |
|
| 60 | 60 | $lang['auth.activate_no_user'] = 'Unable to find a user with those credentials.'; |
| 61 | 61 | $lang['auth.remind_subject'] = "Here's how to reset your password..."; |
| 62 | 62 | $lang['auth.need_reset_code'] = 'You must provide the Reset Code.'; |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?= form_open( current_url(), ['id' => 'login_form']); ?> |
|
| 1 | +<?= form_open(current_url(), ['id' => 'login_form']); ?> |
|
| 2 | 2 | |
| 3 | 3 | <h2 class="form-signin-heading"><?= lang('auth.signin') ?></h2> |
| 4 | 4 | |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?= form_open( current_url(), ['id' => 'join_form'] ) ?> |
|
| 1 | +<?= form_open(current_url(), ['id' => 'join_form']) ?> |
|
| 2 | 2 | |
| 3 | 3 | <h2 class="form-signin-heading"><?= lang('auth.register') ?></h2> |
| 4 | 4 | |
@@ -37,325 +37,325 @@ |
||
| 37 | 37 | // todo Add ability to log actual cron jobs to database to verify when they ran for sure. |
| 38 | 38 | class Cron extends \Myth\Controllers\CLIController { |
| 39 | 39 | |
| 40 | - protected $descriptions = [ |
|
| 41 | - 'show' => ['show [all/<task>]', 'Lists the names one or more tasks, with run times.'], |
|
| 42 | - 'run' => ['run [<task>]', 'Runs all scheduled tasks. If <task> is present only runs that task.'], |
|
| 43 | - 'disable' => ['disable', 'Disables the cron system and will not run any tasks.'], |
|
| 44 | - 'enable' => ['enable', 'Enables the cron system and will run tasks again.'], |
|
| 45 | - 'suspend' => ['suspend <task>', 'Stops a single task from running until resumed.'], |
|
| 46 | - 'resume' => ['resume <task>', 'Resumes execution of a single suspended task.'] |
|
| 47 | - ]; |
|
| 48 | - |
|
| 49 | - protected $long_descriptions = [ |
|
| 50 | - 'show' => '', |
|
| 51 | - 'run' => '', |
|
| 52 | - 'disable' => '', |
|
| 53 | - 'enable' => '', |
|
| 54 | - 'suspend' => '', |
|
| 55 | - 'resume' => '' |
|
| 56 | - ]; |
|
| 57 | - |
|
| 58 | - //-------------------------------------------------------------------- |
|
| 59 | - |
|
| 60 | - public function __construct() |
|
| 61 | - { |
|
| 62 | - parent::__construct(); |
|
| 63 | - |
|
| 64 | - // Load our tasks into the sytem. |
|
| 65 | - require APPPATH .'config/cron.php'; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - //-------------------------------------------------------------------- |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Runs all of the tasks (after checking their time, of course...) |
|
| 72 | - * |
|
| 73 | - * @param string $alias |
|
| 74 | - * @return mixed |
|
| 75 | - */ |
|
| 76 | - public function run($alias=null) |
|
| 77 | - { |
|
| 78 | - // Has the system been disabled? |
|
| 79 | - if (Settings::get('is_disabled', 'cron') == 'y') |
|
| 80 | - { |
|
| 81 | - return CLI::error('The cron system has been disabled. No tasks were run.'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $force_run = false; |
|
| 85 | - |
|
| 86 | - // Run one task or all? |
|
| 87 | - if (! empty($alias)) |
|
| 88 | - { |
|
| 89 | - $tasks = \Myth\Cron\CronManager::task($alias); |
|
| 90 | - |
|
| 91 | - if (is_null($tasks)) |
|
| 92 | - { |
|
| 93 | - return CLI::error("Unable to find the task: '{$alias}'."); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $tasks = [ $alias => $tasks]; |
|
| 97 | - $force_run = true; |
|
| 98 | - } |
|
| 99 | - else |
|
| 100 | - { |
|
| 101 | - $tasks = \Myth\Cron\CronManager::tasks(); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if (empty($tasks)) |
|
| 105 | - { |
|
| 106 | - return CLI::write("There are no tasks to run at this time."); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // We need to be able to check against suspended tasks. |
|
| 110 | - $suspended = Settings::get('suspended_tasks', 'cron'); |
|
| 111 | - |
|
| 112 | - if (! is_array($suspended)) |
|
| 113 | - { |
|
| 114 | - $suspended = array($suspended); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // Loop over all of our tasks, checking them against the |
|
| 118 | - // suspended tasks to see if they're okay to run. |
|
| 119 | - |
|
| 120 | - // Collect the output of the actions so that we can make |
|
| 121 | - // it available to the event (for sending emails and the like) |
|
| 122 | - $output = ''; |
|
| 123 | - |
|
| 124 | - echo CLI::write('Starting Tasks...'); |
|
| 125 | - |
|
| 126 | - foreach ($tasks as $alias => $task) |
|
| 127 | - { |
|
| 128 | - if (in_array($alias, $suspended)) |
|
| 129 | - { |
|
| 130 | - echo CLI::write("\t[Suspended] {$alias} will not run until resumed.", 'yellow'); |
|
| 131 | - $output .= "[Suspended] {$alias} will not run until resumed."; |
|
| 132 | - continue; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - echo CLI::write("\tRunning task: {$alias}..."); |
|
| 136 | - $output .= \Myth\Cron\CronManager::run($alias, $force_run); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - // Give other people a chance to respond. |
|
| 140 | - echo CLI::write('Done. Firing the event so others can play too...'); |
|
| 141 | - |
|
| 142 | - Events::trigger('afterCron', [$output]); |
|
| 143 | - |
|
| 144 | - // And we're out of here boys and girls! |
|
| 145 | - echo CLI::write('Done'); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - //-------------------------------------------------------------------- |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Lists one or more tasks with their scheduled run times. |
|
| 153 | - * |
|
| 154 | - * @param null $task |
|
| 155 | - * @return mixed |
|
| 156 | - */ |
|
| 157 | - public function show($task=null) |
|
| 158 | - { |
|
| 159 | - if (empty($task)) |
|
| 160 | - { |
|
| 161 | - return $this->listTaskNames(); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if (trim(strtolower($task)) == 'all') |
|
| 165 | - { |
|
| 166 | - $tasks = \Myth\Cron\CronManager::listAll(); |
|
| 167 | - } |
|
| 168 | - else |
|
| 169 | - { |
|
| 170 | - $tasks = \Myth\Cron\CronManager::task($task); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if (! is_array($tasks)) |
|
| 174 | - { |
|
| 175 | - $tasks = [ $task => [ |
|
| 176 | - 'next_run' => $tasks->nextRunDate(), |
|
| 177 | - 'prev_run' => $tasks->previousRunDate() |
|
| 178 | - ]]; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if (! count($tasks)) |
|
| 182 | - { |
|
| 183 | - return CLI::found('No tasks found.', 'red'); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $suspended = Settings::get('suspended_tasks', 'cron'); |
|
| 187 | - |
|
| 188 | - if (empty($suspended)) |
|
| 189 | - { |
|
| 190 | - $suspended = []; |
|
| 191 | - } |
|
| 192 | - /* |
|
| 40 | + protected $descriptions = [ |
|
| 41 | + 'show' => ['show [all/<task>]', 'Lists the names one or more tasks, with run times.'], |
|
| 42 | + 'run' => ['run [<task>]', 'Runs all scheduled tasks. If <task> is present only runs that task.'], |
|
| 43 | + 'disable' => ['disable', 'Disables the cron system and will not run any tasks.'], |
|
| 44 | + 'enable' => ['enable', 'Enables the cron system and will run tasks again.'], |
|
| 45 | + 'suspend' => ['suspend <task>', 'Stops a single task from running until resumed.'], |
|
| 46 | + 'resume' => ['resume <task>', 'Resumes execution of a single suspended task.'] |
|
| 47 | + ]; |
|
| 48 | + |
|
| 49 | + protected $long_descriptions = [ |
|
| 50 | + 'show' => '', |
|
| 51 | + 'run' => '', |
|
| 52 | + 'disable' => '', |
|
| 53 | + 'enable' => '', |
|
| 54 | + 'suspend' => '', |
|
| 55 | + 'resume' => '' |
|
| 56 | + ]; |
|
| 57 | + |
|
| 58 | + //-------------------------------------------------------------------- |
|
| 59 | + |
|
| 60 | + public function __construct() |
|
| 61 | + { |
|
| 62 | + parent::__construct(); |
|
| 63 | + |
|
| 64 | + // Load our tasks into the sytem. |
|
| 65 | + require APPPATH .'config/cron.php'; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + //-------------------------------------------------------------------- |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Runs all of the tasks (after checking their time, of course...) |
|
| 72 | + * |
|
| 73 | + * @param string $alias |
|
| 74 | + * @return mixed |
|
| 75 | + */ |
|
| 76 | + public function run($alias=null) |
|
| 77 | + { |
|
| 78 | + // Has the system been disabled? |
|
| 79 | + if (Settings::get('is_disabled', 'cron') == 'y') |
|
| 80 | + { |
|
| 81 | + return CLI::error('The cron system has been disabled. No tasks were run.'); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $force_run = false; |
|
| 85 | + |
|
| 86 | + // Run one task or all? |
|
| 87 | + if (! empty($alias)) |
|
| 88 | + { |
|
| 89 | + $tasks = \Myth\Cron\CronManager::task($alias); |
|
| 90 | + |
|
| 91 | + if (is_null($tasks)) |
|
| 92 | + { |
|
| 93 | + return CLI::error("Unable to find the task: '{$alias}'."); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $tasks = [ $alias => $tasks]; |
|
| 97 | + $force_run = true; |
|
| 98 | + } |
|
| 99 | + else |
|
| 100 | + { |
|
| 101 | + $tasks = \Myth\Cron\CronManager::tasks(); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if (empty($tasks)) |
|
| 105 | + { |
|
| 106 | + return CLI::write("There are no tasks to run at this time."); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // We need to be able to check against suspended tasks. |
|
| 110 | + $suspended = Settings::get('suspended_tasks', 'cron'); |
|
| 111 | + |
|
| 112 | + if (! is_array($suspended)) |
|
| 113 | + { |
|
| 114 | + $suspended = array($suspended); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // Loop over all of our tasks, checking them against the |
|
| 118 | + // suspended tasks to see if they're okay to run. |
|
| 119 | + |
|
| 120 | + // Collect the output of the actions so that we can make |
|
| 121 | + // it available to the event (for sending emails and the like) |
|
| 122 | + $output = ''; |
|
| 123 | + |
|
| 124 | + echo CLI::write('Starting Tasks...'); |
|
| 125 | + |
|
| 126 | + foreach ($tasks as $alias => $task) |
|
| 127 | + { |
|
| 128 | + if (in_array($alias, $suspended)) |
|
| 129 | + { |
|
| 130 | + echo CLI::write("\t[Suspended] {$alias} will not run until resumed.", 'yellow'); |
|
| 131 | + $output .= "[Suspended] {$alias} will not run until resumed."; |
|
| 132 | + continue; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + echo CLI::write("\tRunning task: {$alias}..."); |
|
| 136 | + $output .= \Myth\Cron\CronManager::run($alias, $force_run); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + // Give other people a chance to respond. |
|
| 140 | + echo CLI::write('Done. Firing the event so others can play too...'); |
|
| 141 | + |
|
| 142 | + Events::trigger('afterCron', [$output]); |
|
| 143 | + |
|
| 144 | + // And we're out of here boys and girls! |
|
| 145 | + echo CLI::write('Done'); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + //-------------------------------------------------------------------- |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Lists one or more tasks with their scheduled run times. |
|
| 153 | + * |
|
| 154 | + * @param null $task |
|
| 155 | + * @return mixed |
|
| 156 | + */ |
|
| 157 | + public function show($task=null) |
|
| 158 | + { |
|
| 159 | + if (empty($task)) |
|
| 160 | + { |
|
| 161 | + return $this->listTaskNames(); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if (trim(strtolower($task)) == 'all') |
|
| 165 | + { |
|
| 166 | + $tasks = \Myth\Cron\CronManager::listAll(); |
|
| 167 | + } |
|
| 168 | + else |
|
| 169 | + { |
|
| 170 | + $tasks = \Myth\Cron\CronManager::task($task); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if (! is_array($tasks)) |
|
| 174 | + { |
|
| 175 | + $tasks = [ $task => [ |
|
| 176 | + 'next_run' => $tasks->nextRunDate(), |
|
| 177 | + 'prev_run' => $tasks->previousRunDate() |
|
| 178 | + ]]; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if (! count($tasks)) |
|
| 182 | + { |
|
| 183 | + return CLI::found('No tasks found.', 'red'); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $suspended = Settings::get('suspended_tasks', 'cron'); |
|
| 187 | + |
|
| 188 | + if (empty($suspended)) |
|
| 189 | + { |
|
| 190 | + $suspended = []; |
|
| 191 | + } |
|
| 192 | + /* |
|
| 193 | 193 | * Headers |
| 194 | 194 | */ |
| 195 | - echo CLI::write("Task\t\t\t\tNext Run\t\tPrevious Run"); |
|
| 196 | - echo CLI::write( str_repeat('-', 80) ); |
|
| 197 | - |
|
| 198 | - foreach ($tasks as $alias => $task) |
|
| 199 | - { |
|
| 200 | - // Suspended? |
|
| 201 | - $color = 'yellow'; |
|
| 202 | - $extra = ''; |
|
| 203 | - |
|
| 204 | - if (in_array($alias, $suspended) ) |
|
| 205 | - { |
|
| 206 | - $color = 'blue'; |
|
| 207 | - $extra = "\t[Suspended]"; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // Alias can only be 24 chars long. |
|
| 211 | - $alias = strlen($alias) >= 32 ? substr($alias, 0, 28) .'... ' : $alias . str_repeat(" ", 32 - strlen($alias)); |
|
| 212 | - |
|
| 213 | - $next = date('D Y-m-d H:i', $task['next_run']); |
|
| 214 | - $prev = date('D Y-m-d H:i', $task['prev_run']); |
|
| 215 | - |
|
| 216 | - echo CLI::write("{$alias}{$next}\t{$prev}{$extra}", $color); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - //-------------------------------------------------------------------- |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Stops a task from being executed during the normal cron runs. |
|
| 224 | - * |
|
| 225 | - * @param $alias |
|
| 226 | - */ |
|
| 227 | - public function suspend($alias) |
|
| 228 | - { |
|
| 229 | - // Verify the task actually exists. |
|
| 230 | - $task = \Myth\Cron\CronManager::task($alias); |
|
| 231 | - |
|
| 232 | - if (is_null($task)) |
|
| 233 | - { |
|
| 234 | - return CLI::error("Unable to find the task: {$alias}."); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // Update the existing setting. |
|
| 238 | - $suspended = Settings::get('suspended_tasks', 'cron'); |
|
| 239 | - |
|
| 240 | - if (empty($suspended)) |
|
| 241 | - { |
|
| 242 | - $suspended = []; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - $suspended[] = $alias; |
|
| 246 | - |
|
| 247 | - if (Settings::save('suspended_tasks', $suspended, 'cron') ) |
|
| 248 | - { |
|
| 249 | - return CLI::write('Done'); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - echo CLI::error('Unkown problem saving the settings.'); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - //-------------------------------------------------------------------- |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Allows the execution of a suspended task to continue again |
|
| 259 | - * during normal cron execution. |
|
| 260 | - * |
|
| 261 | - * @param $alias |
|
| 262 | - */ |
|
| 263 | - public function resume($alias) |
|
| 264 | - { |
|
| 265 | - // Verify the task actually exists. |
|
| 266 | - $task = \Myth\Cron\CronManager::task($alias); |
|
| 267 | - |
|
| 268 | - if (is_null($task)) |
|
| 269 | - { |
|
| 270 | - return CLI::error("Unable to find the task: {$alias}."); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // Update the existing setting. |
|
| 274 | - $suspended = Settings::get('suspended_tasks', 'cron'); |
|
| 275 | - |
|
| 276 | - if (! empty($suspended)) |
|
| 277 | - { |
|
| 278 | - unset($suspended[ array_search($alias, $suspended) ]); |
|
| 279 | - |
|
| 280 | - if (! Settings::save('suspended_tasks', $suspended, 'cron') ) |
|
| 281 | - { |
|
| 282 | - return CLI::error('Unkown problem saving the settings.'); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - return CLI::write('Done'); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - //-------------------------------------------------------------------- |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Disables the cron tasks and stops the system from running any tasks. |
|
| 293 | - * To start the system allowing it to run again, use the `enable` command. |
|
| 294 | - */ |
|
| 295 | - public function disable() |
|
| 296 | - { |
|
| 297 | - if (! Settings::save('is_disabled', 'y', 'cron')) |
|
| 298 | - { |
|
| 299 | - return CLI::error('Unknown problem saving the setting. '. CLI::color('Cron jobs will still run!', 'yellow')); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - CLI::write('Done'); |
|
| 303 | - } |
|
| 195 | + echo CLI::write("Task\t\t\t\tNext Run\t\tPrevious Run"); |
|
| 196 | + echo CLI::write( str_repeat('-', 80) ); |
|
| 197 | + |
|
| 198 | + foreach ($tasks as $alias => $task) |
|
| 199 | + { |
|
| 200 | + // Suspended? |
|
| 201 | + $color = 'yellow'; |
|
| 202 | + $extra = ''; |
|
| 203 | + |
|
| 204 | + if (in_array($alias, $suspended) ) |
|
| 205 | + { |
|
| 206 | + $color = 'blue'; |
|
| 207 | + $extra = "\t[Suspended]"; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // Alias can only be 24 chars long. |
|
| 211 | + $alias = strlen($alias) >= 32 ? substr($alias, 0, 28) .'... ' : $alias . str_repeat(" ", 32 - strlen($alias)); |
|
| 212 | + |
|
| 213 | + $next = date('D Y-m-d H:i', $task['next_run']); |
|
| 214 | + $prev = date('D Y-m-d H:i', $task['prev_run']); |
|
| 215 | + |
|
| 216 | + echo CLI::write("{$alias}{$next}\t{$prev}{$extra}", $color); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + //-------------------------------------------------------------------- |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Stops a task from being executed during the normal cron runs. |
|
| 224 | + * |
|
| 225 | + * @param $alias |
|
| 226 | + */ |
|
| 227 | + public function suspend($alias) |
|
| 228 | + { |
|
| 229 | + // Verify the task actually exists. |
|
| 230 | + $task = \Myth\Cron\CronManager::task($alias); |
|
| 231 | + |
|
| 232 | + if (is_null($task)) |
|
| 233 | + { |
|
| 234 | + return CLI::error("Unable to find the task: {$alias}."); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // Update the existing setting. |
|
| 238 | + $suspended = Settings::get('suspended_tasks', 'cron'); |
|
| 239 | + |
|
| 240 | + if (empty($suspended)) |
|
| 241 | + { |
|
| 242 | + $suspended = []; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + $suspended[] = $alias; |
|
| 246 | + |
|
| 247 | + if (Settings::save('suspended_tasks', $suspended, 'cron') ) |
|
| 248 | + { |
|
| 249 | + return CLI::write('Done'); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + echo CLI::error('Unkown problem saving the settings.'); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + //-------------------------------------------------------------------- |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Allows the execution of a suspended task to continue again |
|
| 259 | + * during normal cron execution. |
|
| 260 | + * |
|
| 261 | + * @param $alias |
|
| 262 | + */ |
|
| 263 | + public function resume($alias) |
|
| 264 | + { |
|
| 265 | + // Verify the task actually exists. |
|
| 266 | + $task = \Myth\Cron\CronManager::task($alias); |
|
| 267 | + |
|
| 268 | + if (is_null($task)) |
|
| 269 | + { |
|
| 270 | + return CLI::error("Unable to find the task: {$alias}."); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // Update the existing setting. |
|
| 274 | + $suspended = Settings::get('suspended_tasks', 'cron'); |
|
| 275 | + |
|
| 276 | + if (! empty($suspended)) |
|
| 277 | + { |
|
| 278 | + unset($suspended[ array_search($alias, $suspended) ]); |
|
| 279 | + |
|
| 280 | + if (! Settings::save('suspended_tasks', $suspended, 'cron') ) |
|
| 281 | + { |
|
| 282 | + return CLI::error('Unkown problem saving the settings.'); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + return CLI::write('Done'); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + //-------------------------------------------------------------------- |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Disables the cron tasks and stops the system from running any tasks. |
|
| 293 | + * To start the system allowing it to run again, use the `enable` command. |
|
| 294 | + */ |
|
| 295 | + public function disable() |
|
| 296 | + { |
|
| 297 | + if (! Settings::save('is_disabled', 'y', 'cron')) |
|
| 298 | + { |
|
| 299 | + return CLI::error('Unknown problem saving the setting. '. CLI::color('Cron jobs will still run!', 'yellow')); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + CLI::write('Done'); |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | - //-------------------------------------------------------------------- |
|
| 305 | + //-------------------------------------------------------------------- |
|
| 306 | 306 | |
| 307 | - /** |
|
| 308 | - * Resumes the running of tasks after the system has been disabled |
|
| 309 | - * with the `disable` command. |
|
| 310 | - */ |
|
| 311 | - public function enable() |
|
| 312 | - { |
|
| 313 | - if (! Settings::save('is_disabled', 'n', 'cron')) |
|
| 314 | - { |
|
| 315 | - return CLI::error('Unknown problem saving the setting. '. CLI::color('Cron jobs will NOT run!', 'yellow')); |
|
| 316 | - } |
|
| 307 | + /** |
|
| 308 | + * Resumes the running of tasks after the system has been disabled |
|
| 309 | + * with the `disable` command. |
|
| 310 | + */ |
|
| 311 | + public function enable() |
|
| 312 | + { |
|
| 313 | + if (! Settings::save('is_disabled', 'n', 'cron')) |
|
| 314 | + { |
|
| 315 | + return CLI::error('Unknown problem saving the setting. '. CLI::color('Cron jobs will NOT run!', 'yellow')); |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - CLI::write('Done'); |
|
| 319 | - } |
|
| 318 | + CLI::write('Done'); |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | - //-------------------------------------------------------------------- |
|
| 321 | + //-------------------------------------------------------------------- |
|
| 322 | 322 | |
| 323 | 323 | |
| 324 | - //-------------------------------------------------------------------- |
|
| 325 | - // Private Methods |
|
| 326 | - //-------------------------------------------------------------------- |
|
| 324 | + //-------------------------------------------------------------------- |
|
| 325 | + // Private Methods |
|
| 326 | + //-------------------------------------------------------------------- |
|
| 327 | 327 | |
| 328 | - /** |
|
| 329 | - * Lists out all available tasks, names only. |
|
| 330 | - */ |
|
| 331 | - private function listTaskNames() |
|
| 332 | - { |
|
| 333 | - $suspended = Settings::get('suspended_tasks', 'cron'); |
|
| 328 | + /** |
|
| 329 | + * Lists out all available tasks, names only. |
|
| 330 | + */ |
|
| 331 | + private function listTaskNames() |
|
| 332 | + { |
|
| 333 | + $suspended = Settings::get('suspended_tasks', 'cron'); |
|
| 334 | 334 | |
| 335 | - if (empty($suspended)) |
|
| 336 | - { |
|
| 337 | - $suspended = []; |
|
| 338 | - } |
|
| 335 | + if (empty($suspended)) |
|
| 336 | + { |
|
| 337 | + $suspended = []; |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - $tasks = \Myth\Cron\CronManager::listAll(); |
|
| 340 | + $tasks = \Myth\Cron\CronManager::listAll(); |
|
| 341 | 341 | |
| 342 | - echo CLI::write("\nAvailable Tasks:"); |
|
| 342 | + echo CLI::write("\nAvailable Tasks:"); |
|
| 343 | 343 | |
| 344 | - foreach ($tasks as $alias => $task) |
|
| 345 | - { |
|
| 346 | - $color = 'yellow'; |
|
| 347 | - $extra = ''; |
|
| 344 | + foreach ($tasks as $alias => $task) |
|
| 345 | + { |
|
| 346 | + $color = 'yellow'; |
|
| 347 | + $extra = ''; |
|
| 348 | 348 | |
| 349 | - if (in_array($alias, $suspended) ) |
|
| 350 | - { |
|
| 351 | - $color = 'blue'; |
|
| 352 | - $extra = "[Suspended]"; |
|
| 353 | - } |
|
| 349 | + if (in_array($alias, $suspended) ) |
|
| 350 | + { |
|
| 351 | + $color = 'blue'; |
|
| 352 | + $extra = "[Suspended]"; |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - echo CLI::write("\t{$extra} {$alias}", $color); |
|
| 356 | - } |
|
| 357 | - } |
|
| 355 | + echo CLI::write("\t{$extra} {$alias}", $color); |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | - //-------------------------------------------------------------------- |
|
| 359 | + //-------------------------------------------------------------------- |
|
| 360 | 360 | |
| 361 | 361 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | parent::__construct(); |
| 63 | 63 | |
| 64 | 64 | // Load our tasks into the sytem. |
| 65 | - require APPPATH .'config/cron.php'; |
|
| 65 | + require APPPATH.'config/cron.php'; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | //-------------------------------------------------------------------- |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @param string $alias |
| 74 | 74 | * @return mixed |
| 75 | 75 | */ |
| 76 | - public function run($alias=null) |
|
| 76 | + public function run($alias = null) |
|
| 77 | 77 | { |
| 78 | 78 | // Has the system been disabled? |
| 79 | 79 | if (Settings::get('is_disabled', 'cron') == 'y') |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $force_run = false; |
| 85 | 85 | |
| 86 | 86 | // Run one task or all? |
| 87 | - if (! empty($alias)) |
|
| 87 | + if ( ! empty($alias)) |
|
| 88 | 88 | { |
| 89 | 89 | $tasks = \Myth\Cron\CronManager::task($alias); |
| 90 | 90 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | return CLI::error("Unable to find the task: '{$alias}'."); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - $tasks = [ $alias => $tasks]; |
|
| 96 | + $tasks = [$alias => $tasks]; |
|
| 97 | 97 | $force_run = true; |
| 98 | 98 | } |
| 99 | 99 | else |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | // We need to be able to check against suspended tasks. |
| 110 | 110 | $suspended = Settings::get('suspended_tasks', 'cron'); |
| 111 | 111 | |
| 112 | - if (! is_array($suspended)) |
|
| 112 | + if ( ! is_array($suspended)) |
|
| 113 | 113 | { |
| 114 | 114 | $suspended = array($suspended); |
| 115 | 115 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @param null $task |
| 155 | 155 | * @return mixed |
| 156 | 156 | */ |
| 157 | - public function show($task=null) |
|
| 157 | + public function show($task = null) |
|
| 158 | 158 | { |
| 159 | 159 | if (empty($task)) |
| 160 | 160 | { |
@@ -170,15 +170,15 @@ discard block |
||
| 170 | 170 | $tasks = \Myth\Cron\CronManager::task($task); |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - if (! is_array($tasks)) |
|
| 173 | + if ( ! is_array($tasks)) |
|
| 174 | 174 | { |
| 175 | - $tasks = [ $task => [ |
|
| 175 | + $tasks = [$task => [ |
|
| 176 | 176 | 'next_run' => $tasks->nextRunDate(), |
| 177 | 177 | 'prev_run' => $tasks->previousRunDate() |
| 178 | 178 | ]]; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - if (! count($tasks)) |
|
| 181 | + if ( ! count($tasks)) |
|
| 182 | 182 | { |
| 183 | 183 | return CLI::found('No tasks found.', 'red'); |
| 184 | 184 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * Headers |
| 194 | 194 | */ |
| 195 | 195 | echo CLI::write("Task\t\t\t\tNext Run\t\tPrevious Run"); |
| 196 | - echo CLI::write( str_repeat('-', 80) ); |
|
| 196 | + echo CLI::write(str_repeat('-', 80)); |
|
| 197 | 197 | |
| 198 | 198 | foreach ($tasks as $alias => $task) |
| 199 | 199 | { |
@@ -201,14 +201,14 @@ discard block |
||
| 201 | 201 | $color = 'yellow'; |
| 202 | 202 | $extra = ''; |
| 203 | 203 | |
| 204 | - if (in_array($alias, $suspended) ) |
|
| 204 | + if (in_array($alias, $suspended)) |
|
| 205 | 205 | { |
| 206 | 206 | $color = 'blue'; |
| 207 | 207 | $extra = "\t[Suspended]"; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // Alias can only be 24 chars long. |
| 211 | - $alias = strlen($alias) >= 32 ? substr($alias, 0, 28) .'... ' : $alias . str_repeat(" ", 32 - strlen($alias)); |
|
| 211 | + $alias = strlen($alias) >= 32 ? substr($alias, 0, 28).'... ' : $alias.str_repeat(" ", 32 - strlen($alias)); |
|
| 212 | 212 | |
| 213 | 213 | $next = date('D Y-m-d H:i', $task['next_run']); |
| 214 | 214 | $prev = date('D Y-m-d H:i', $task['prev_run']); |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | |
| 245 | 245 | $suspended[] = $alias; |
| 246 | 246 | |
| 247 | - if (Settings::save('suspended_tasks', $suspended, 'cron') ) |
|
| 247 | + if (Settings::save('suspended_tasks', $suspended, 'cron')) |
|
| 248 | 248 | { |
| 249 | 249 | return CLI::write('Done'); |
| 250 | 250 | } |
@@ -273,11 +273,11 @@ discard block |
||
| 273 | 273 | // Update the existing setting. |
| 274 | 274 | $suspended = Settings::get('suspended_tasks', 'cron'); |
| 275 | 275 | |
| 276 | - if (! empty($suspended)) |
|
| 276 | + if ( ! empty($suspended)) |
|
| 277 | 277 | { |
| 278 | - unset($suspended[ array_search($alias, $suspended) ]); |
|
| 278 | + unset($suspended[array_search($alias, $suspended)]); |
|
| 279 | 279 | |
| 280 | - if (! Settings::save('suspended_tasks', $suspended, 'cron') ) |
|
| 280 | + if ( ! Settings::save('suspended_tasks', $suspended, 'cron')) |
|
| 281 | 281 | { |
| 282 | 282 | return CLI::error('Unkown problem saving the settings.'); |
| 283 | 283 | } |
@@ -294,9 +294,9 @@ discard block |
||
| 294 | 294 | */ |
| 295 | 295 | public function disable() |
| 296 | 296 | { |
| 297 | - if (! Settings::save('is_disabled', 'y', 'cron')) |
|
| 297 | + if ( ! Settings::save('is_disabled', 'y', 'cron')) |
|
| 298 | 298 | { |
| 299 | - return CLI::error('Unknown problem saving the setting. '. CLI::color('Cron jobs will still run!', 'yellow')); |
|
| 299 | + return CLI::error('Unknown problem saving the setting. '.CLI::color('Cron jobs will still run!', 'yellow')); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | CLI::write('Done'); |
@@ -310,9 +310,9 @@ discard block |
||
| 310 | 310 | */ |
| 311 | 311 | public function enable() |
| 312 | 312 | { |
| 313 | - if (! Settings::save('is_disabled', 'n', 'cron')) |
|
| 313 | + if ( ! Settings::save('is_disabled', 'n', 'cron')) |
|
| 314 | 314 | { |
| 315 | - return CLI::error('Unknown problem saving the setting. '. CLI::color('Cron jobs will NOT run!', 'yellow')); |
|
| 315 | + return CLI::error('Unknown problem saving the setting. '.CLI::color('Cron jobs will NOT run!', 'yellow')); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | CLI::write('Done'); |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | $color = 'yellow'; |
| 347 | 347 | $extra = ''; |
| 348 | 348 | |
| 349 | - if (in_array($alias, $suspended) ) |
|
| 349 | + if (in_array($alias, $suspended)) |
|
| 350 | 350 | { |
| 351 | 351 | $color = 'blue'; |
| 352 | 352 | $extra = "[Suspended]"; |
@@ -179,8 +179,7 @@ discard block |
||
| 179 | 179 | if (! empty($name)) |
| 180 | 180 | { |
| 181 | 181 | $this->from = [$email, $name]; |
| 182 | - } |
|
| 183 | - else |
|
| 182 | + } else |
|
| 184 | 183 | { |
| 185 | 184 | $this->from = $email; |
| 186 | 185 | } |
@@ -231,8 +230,7 @@ discard block |
||
| 231 | 230 | if (! empty($name)) |
| 232 | 231 | { |
| 233 | 232 | $this->reply_to = [$email, $name]; |
| 234 | - } |
|
| 235 | - else |
|
| 233 | + } else |
|
| 236 | 234 | { |
| 237 | 235 | $this->reply_to = $email; |
| 238 | 236 | } |
@@ -35,207 +35,207 @@ discard block |
||
| 35 | 35 | class Database extends \Myth\Controllers\CLIController |
| 36 | 36 | { |
| 37 | 37 | |
| 38 | - protected $descriptions = [ |
|
| 39 | - 'migrate' => ['migrate [$to]', 'Runs the migrations up or down until schema at version \$to'], |
|
| 40 | - 'quietMigrate' => ['quiteMigrate [$to]', 'Same as migrate but without any feedback.'], |
|
| 41 | - 'refresh' => ['refresh', 'Runs migrations back to version 0 (uninstall) and then back to the most recent migration.'], |
|
| 42 | - 'newMigration' => ['newMigration [$name]', 'Creates a new migration file.'], |
|
| 43 | - 'seed' => ['seed [$name]', 'Runs the named database seeder.'] |
|
| 44 | - ]; |
|
| 45 | - |
|
| 46 | - protected $long_descriptions = [ |
|
| 47 | - 'migrate' => '', |
|
| 48 | - 'quietMigrate' => '', |
|
| 49 | - 'refresh' => '', |
|
| 50 | - 'newMigration' => '', |
|
| 51 | - 'seed' => '' |
|
| 52 | - ]; |
|
| 53 | - |
|
| 54 | - //------------------------------------------------------------------- |
|
| 55 | - |
|
| 56 | - //-------------------------------------------------------------------- |
|
| 57 | - // Migration Methods |
|
| 58 | - //-------------------------------------------------------------------- |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Provides a command-line interface to the migration scripts. |
|
| 62 | - * If no $to is provided, will migrate to the latest version. |
|
| 63 | - * |
|
| 64 | - * Example: |
|
| 65 | - * > php index.php database migrate |
|
| 66 | - * |
|
| 67 | - * @param string $type 'app', 'myth', 'all' or {module_name} |
|
| 68 | - * @param null $to |
|
| 69 | - * @param bool $silent If TRUE, will NOT display any prompts for verification. |
|
| 70 | - * @return bool|void |
|
| 71 | - */ |
|
| 72 | - public function migrate($type=null, $to = null, $silent = false) |
|
| 73 | - { |
|
| 74 | - $this->load->library('migration'); |
|
| 75 | - |
|
| 76 | - if (empty($type)) |
|
| 77 | - { |
|
| 78 | - $type = CLI::prompt("Migration group to refresh?", $this->migration->default_migration_path()); |
|
| 79 | - |
|
| 80 | - if (empty($type)) |
|
| 81 | - { |
|
| 82 | - return $silent ? false : CLI::error("\tYou must supply a group to refresh."); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // We need to append 'mod:' to properly handle modules, if |
|
| 87 | - // the $type is not one of the recognized migration groups. |
|
| 88 | - $this->config->load('migration'); |
|
| 89 | - $groups = config_item('migration_paths'); |
|
| 90 | - $groups = array_keys($groups); |
|
| 91 | - |
|
| 92 | - // If it's not in the groups list, then assume it's a module. |
|
| 93 | - if (! in_array($type, $groups)) |
|
| 94 | - { |
|
| 95 | - if (strpos($type, 'mod:') !== 0) |
|
| 96 | - { |
|
| 97 | - $type = 'mod:'. $type; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - unset($groups); |
|
| 102 | - |
|
| 103 | - // Get our stats on the migrations |
|
| 104 | - $latest = $this->migration->get_latest($type); |
|
| 105 | - $latest = empty($latest) ? 0 : substr($latest, 0, strpos($latest, '_')); |
|
| 106 | - |
|
| 107 | - if (empty($latest)) { |
|
| 108 | - return CLI::write("\tNo migrations found.", 'yellow'); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $current = $this->migration->get_version($type); |
|
| 112 | - |
|
| 113 | - // Already at the desired version? |
|
| 114 | - if ((! is_null($to) && $current == $to) OR (is_null($to) && $current == $latest)) |
|
| 115 | - { |
|
| 116 | - return $silent ? true : CLI::write("\tDatabase is already at the desired version ({$current})", 'yellow'); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $target = is_null($to) ? $latest : $to; |
|
| 120 | - |
|
| 121 | - // Just to be safe, verify with the user they want to migrate |
|
| 122 | - // to the latest version. |
|
| 123 | - if (is_null($to)) { |
|
| 124 | - // If we're in silent mode, don't prompt, just go to the latest... |
|
| 125 | - if (! $silent) { |
|
| 126 | - $go_ahead = CLI::prompt('Migrate to the latest available version?', array('y', 'n')); |
|
| 127 | - |
|
| 128 | - if ($go_ahead == 'n') { |
|
| 129 | - return CLI::write('Bailing...', 'yellow'); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - if (! $this->migration->latest($type)) { |
|
| 134 | - return CLI::error("\n\tERROR: " . $this->migration->error_string() . "\n"); |
|
| 135 | - } |
|
| 136 | - } else { |
|
| 137 | - if ($this->migration->version($type, $to) === false) { |
|
| 138 | - return CLI::error("\n\tERROR: " . $this->migration->error_string() . "\n"); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $silent ? true : |
|
| 143 | - CLI::write("\n\tSuccessfully migrated database from version {$current} to {$target}.\n", 'green'); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - //-------------------------------------------------------------------- |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Performs a migration that does not prompt for any information. |
|
| 150 | - * Suitable for use within automated scripts that can't be |
|
| 151 | - * bothered with answering questions. |
|
| 152 | - * |
|
| 153 | - * @param string $type 'app', 'myth', 'all' or {module_name} |
|
| 154 | - * @param null $to |
|
| 155 | - * @return bool|void |
|
| 156 | - */ |
|
| 157 | - public function quietMigrate($type='app', $to = null) |
|
| 158 | - { |
|
| 159 | - return $this->migrate($type, $to, true); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - //-------------------------------------------------------------------- |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Migrates the database back to 0, then back up to the latest version. |
|
| 167 | - * |
|
| 168 | - * @param string $type The group or module to refresh. |
|
| 169 | - * @return mixed |
|
| 170 | - */ |
|
| 171 | - public function refresh($type=null) |
|
| 172 | - { |
|
| 173 | - $this->load->library('migration'); |
|
| 174 | - |
|
| 175 | - if (empty($type)) |
|
| 176 | - { |
|
| 177 | - $type = CLI::prompt("Migration group to refresh?", $this->migration->default_migration_path()); |
|
| 178 | - |
|
| 179 | - if (empty($type)) |
|
| 180 | - { |
|
| 181 | - return CLI::error("\tYou must supply a group to refresh."); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - if ($this->migration->version($type, 0) === false) { |
|
| 186 | - return CLI::error("\tERROR: " . $this->migration->error_string()); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - CLI::write(CLI::color("\tCleared the database.", 'green')); |
|
| 190 | - |
|
| 191 | - if ($this->migration->latest($type) === false) { |
|
| 192 | - return CLI::error("\tERROR: " . $this->migration->error_string()); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - CLI::write("\tRe-installed the database to the latest migration.", 'green'); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - //-------------------------------------------------------------------- |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Creates a new migration file ready to be used. |
|
| 202 | - * |
|
| 203 | - * @param $name |
|
| 204 | - */ |
|
| 205 | - public function newMigration($name = null, $type = 'app') |
|
| 206 | - { |
|
| 207 | - if (empty($name)) { |
|
| 208 | - $name = CLI::prompt('Migration name? '); |
|
| 209 | - |
|
| 210 | - if (empty($name)) { |
|
| 211 | - return CLI::error("\tYou must provide a migration name.", 'red'); |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $this->load->library('migration'); |
|
| 216 | - |
|
| 217 | - $path = $this->migration->determine_migration_path($type); |
|
| 218 | - |
|
| 219 | - // Does the alias path exist in our config? |
|
| 220 | - if (! $path) { |
|
| 221 | - return CLI::error("\tThe migration path for '{$type}' does not exist.'"); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - // Does the path really exist? |
|
| 225 | - if (! is_dir($path)) { |
|
| 226 | - return CLI::error("\tThe path for '{$type}' is not a directory."); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // Is the folder writeable? |
|
| 230 | - if (! is_writeable($path)) { |
|
| 231 | - return CLI::error("\tThe folder for '{$type}' migrations is not writeable."); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $file = $this->migration->make_name($name); |
|
| 235 | - |
|
| 236 | - $path = rtrim($path, '/') .'/'. $file; |
|
| 237 | - |
|
| 238 | - $contents = <<<EOT |
|
| 38 | + protected $descriptions = [ |
|
| 39 | + 'migrate' => ['migrate [$to]', 'Runs the migrations up or down until schema at version \$to'], |
|
| 40 | + 'quietMigrate' => ['quiteMigrate [$to]', 'Same as migrate but without any feedback.'], |
|
| 41 | + 'refresh' => ['refresh', 'Runs migrations back to version 0 (uninstall) and then back to the most recent migration.'], |
|
| 42 | + 'newMigration' => ['newMigration [$name]', 'Creates a new migration file.'], |
|
| 43 | + 'seed' => ['seed [$name]', 'Runs the named database seeder.'] |
|
| 44 | + ]; |
|
| 45 | + |
|
| 46 | + protected $long_descriptions = [ |
|
| 47 | + 'migrate' => '', |
|
| 48 | + 'quietMigrate' => '', |
|
| 49 | + 'refresh' => '', |
|
| 50 | + 'newMigration' => '', |
|
| 51 | + 'seed' => '' |
|
| 52 | + ]; |
|
| 53 | + |
|
| 54 | + //------------------------------------------------------------------- |
|
| 55 | + |
|
| 56 | + //-------------------------------------------------------------------- |
|
| 57 | + // Migration Methods |
|
| 58 | + //-------------------------------------------------------------------- |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Provides a command-line interface to the migration scripts. |
|
| 62 | + * If no $to is provided, will migrate to the latest version. |
|
| 63 | + * |
|
| 64 | + * Example: |
|
| 65 | + * > php index.php database migrate |
|
| 66 | + * |
|
| 67 | + * @param string $type 'app', 'myth', 'all' or {module_name} |
|
| 68 | + * @param null $to |
|
| 69 | + * @param bool $silent If TRUE, will NOT display any prompts for verification. |
|
| 70 | + * @return bool|void |
|
| 71 | + */ |
|
| 72 | + public function migrate($type=null, $to = null, $silent = false) |
|
| 73 | + { |
|
| 74 | + $this->load->library('migration'); |
|
| 75 | + |
|
| 76 | + if (empty($type)) |
|
| 77 | + { |
|
| 78 | + $type = CLI::prompt("Migration group to refresh?", $this->migration->default_migration_path()); |
|
| 79 | + |
|
| 80 | + if (empty($type)) |
|
| 81 | + { |
|
| 82 | + return $silent ? false : CLI::error("\tYou must supply a group to refresh."); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // We need to append 'mod:' to properly handle modules, if |
|
| 87 | + // the $type is not one of the recognized migration groups. |
|
| 88 | + $this->config->load('migration'); |
|
| 89 | + $groups = config_item('migration_paths'); |
|
| 90 | + $groups = array_keys($groups); |
|
| 91 | + |
|
| 92 | + // If it's not in the groups list, then assume it's a module. |
|
| 93 | + if (! in_array($type, $groups)) |
|
| 94 | + { |
|
| 95 | + if (strpos($type, 'mod:') !== 0) |
|
| 96 | + { |
|
| 97 | + $type = 'mod:'. $type; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + unset($groups); |
|
| 102 | + |
|
| 103 | + // Get our stats on the migrations |
|
| 104 | + $latest = $this->migration->get_latest($type); |
|
| 105 | + $latest = empty($latest) ? 0 : substr($latest, 0, strpos($latest, '_')); |
|
| 106 | + |
|
| 107 | + if (empty($latest)) { |
|
| 108 | + return CLI::write("\tNo migrations found.", 'yellow'); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $current = $this->migration->get_version($type); |
|
| 112 | + |
|
| 113 | + // Already at the desired version? |
|
| 114 | + if ((! is_null($to) && $current == $to) OR (is_null($to) && $current == $latest)) |
|
| 115 | + { |
|
| 116 | + return $silent ? true : CLI::write("\tDatabase is already at the desired version ({$current})", 'yellow'); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $target = is_null($to) ? $latest : $to; |
|
| 120 | + |
|
| 121 | + // Just to be safe, verify with the user they want to migrate |
|
| 122 | + // to the latest version. |
|
| 123 | + if (is_null($to)) { |
|
| 124 | + // If we're in silent mode, don't prompt, just go to the latest... |
|
| 125 | + if (! $silent) { |
|
| 126 | + $go_ahead = CLI::prompt('Migrate to the latest available version?', array('y', 'n')); |
|
| 127 | + |
|
| 128 | + if ($go_ahead == 'n') { |
|
| 129 | + return CLI::write('Bailing...', 'yellow'); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + if (! $this->migration->latest($type)) { |
|
| 134 | + return CLI::error("\n\tERROR: " . $this->migration->error_string() . "\n"); |
|
| 135 | + } |
|
| 136 | + } else { |
|
| 137 | + if ($this->migration->version($type, $to) === false) { |
|
| 138 | + return CLI::error("\n\tERROR: " . $this->migration->error_string() . "\n"); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $silent ? true : |
|
| 143 | + CLI::write("\n\tSuccessfully migrated database from version {$current} to {$target}.\n", 'green'); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + //-------------------------------------------------------------------- |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Performs a migration that does not prompt for any information. |
|
| 150 | + * Suitable for use within automated scripts that can't be |
|
| 151 | + * bothered with answering questions. |
|
| 152 | + * |
|
| 153 | + * @param string $type 'app', 'myth', 'all' or {module_name} |
|
| 154 | + * @param null $to |
|
| 155 | + * @return bool|void |
|
| 156 | + */ |
|
| 157 | + public function quietMigrate($type='app', $to = null) |
|
| 158 | + { |
|
| 159 | + return $this->migrate($type, $to, true); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + //-------------------------------------------------------------------- |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Migrates the database back to 0, then back up to the latest version. |
|
| 167 | + * |
|
| 168 | + * @param string $type The group or module to refresh. |
|
| 169 | + * @return mixed |
|
| 170 | + */ |
|
| 171 | + public function refresh($type=null) |
|
| 172 | + { |
|
| 173 | + $this->load->library('migration'); |
|
| 174 | + |
|
| 175 | + if (empty($type)) |
|
| 176 | + { |
|
| 177 | + $type = CLI::prompt("Migration group to refresh?", $this->migration->default_migration_path()); |
|
| 178 | + |
|
| 179 | + if (empty($type)) |
|
| 180 | + { |
|
| 181 | + return CLI::error("\tYou must supply a group to refresh."); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + if ($this->migration->version($type, 0) === false) { |
|
| 186 | + return CLI::error("\tERROR: " . $this->migration->error_string()); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + CLI::write(CLI::color("\tCleared the database.", 'green')); |
|
| 190 | + |
|
| 191 | + if ($this->migration->latest($type) === false) { |
|
| 192 | + return CLI::error("\tERROR: " . $this->migration->error_string()); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + CLI::write("\tRe-installed the database to the latest migration.", 'green'); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + //-------------------------------------------------------------------- |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Creates a new migration file ready to be used. |
|
| 202 | + * |
|
| 203 | + * @param $name |
|
| 204 | + */ |
|
| 205 | + public function newMigration($name = null, $type = 'app') |
|
| 206 | + { |
|
| 207 | + if (empty($name)) { |
|
| 208 | + $name = CLI::prompt('Migration name? '); |
|
| 209 | + |
|
| 210 | + if (empty($name)) { |
|
| 211 | + return CLI::error("\tYou must provide a migration name.", 'red'); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + $this->load->library('migration'); |
|
| 216 | + |
|
| 217 | + $path = $this->migration->determine_migration_path($type); |
|
| 218 | + |
|
| 219 | + // Does the alias path exist in our config? |
|
| 220 | + if (! $path) { |
|
| 221 | + return CLI::error("\tThe migration path for '{$type}' does not exist.'"); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + // Does the path really exist? |
|
| 225 | + if (! is_dir($path)) { |
|
| 226 | + return CLI::error("\tThe path for '{$type}' is not a directory."); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // Is the folder writeable? |
|
| 230 | + if (! is_writeable($path)) { |
|
| 231 | + return CLI::error("\tThe folder for '{$type}' migrations is not writeable."); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $file = $this->migration->make_name($name); |
|
| 235 | + |
|
| 236 | + $path = rtrim($path, '/') .'/'. $file; |
|
| 237 | + |
|
| 238 | + $contents = <<<EOT |
|
| 239 | 239 | <?php |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -262,36 +262,36 @@ discard block |
||
| 262 | 262 | |
| 263 | 263 | } |
| 264 | 264 | EOT; |
| 265 | - $contents = str_replace('{name}', $name, $contents); |
|
| 266 | - $contents = str_replace('{date}', date('Y-m-d H:i:s a'), $contents); |
|
| 267 | - $contents = str_replace('{clean_name}', ucwords(str_replace('_', ' ', $name)), $contents); |
|
| 265 | + $contents = str_replace('{name}', $name, $contents); |
|
| 266 | + $contents = str_replace('{date}', date('Y-m-d H:i:s a'), $contents); |
|
| 267 | + $contents = str_replace('{clean_name}', ucwords(str_replace('_', ' ', $name)), $contents); |
|
| 268 | 268 | |
| 269 | - $this->load->helper('file'); |
|
| 269 | + $this->load->helper('file'); |
|
| 270 | 270 | |
| 271 | - if (write_file($path, $contents)) { |
|
| 272 | - return CLI::write("\tNew migration created: " . CLI::color($file, 'yellow'), 'green'); |
|
| 273 | - } |
|
| 271 | + if (write_file($path, $contents)) { |
|
| 272 | + return CLI::write("\tNew migration created: " . CLI::color($file, 'yellow'), 'green'); |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - return CLI::error("\tUnkown error trying to create migration: {$file}", 'red'); |
|
| 276 | - } |
|
| 275 | + return CLI::error("\tUnkown error trying to create migration: {$file}", 'red'); |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - //-------------------------------------------------------------------- |
|
| 278 | + //-------------------------------------------------------------------- |
|
| 279 | 279 | |
| 280 | - //-------------------------------------------------------------------- |
|
| 281 | - // Seeding Methods |
|
| 282 | - //-------------------------------------------------------------------- |
|
| 280 | + //-------------------------------------------------------------------- |
|
| 281 | + // Seeding Methods |
|
| 282 | + //-------------------------------------------------------------------- |
|
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * Installs any database seeds stored in database/seeds. Seeds just need to |
|
| 286 | - * extend the Seeder class and have a method named run. |
|
| 287 | - */ |
|
| 288 | - public function seed($name = null) |
|
| 289 | - { |
|
| 290 | - $this->load->library('seeder'); |
|
| 284 | + /** |
|
| 285 | + * Installs any database seeds stored in database/seeds. Seeds just need to |
|
| 286 | + * extend the Seeder class and have a method named run. |
|
| 287 | + */ |
|
| 288 | + public function seed($name = null) |
|
| 289 | + { |
|
| 290 | + $this->load->library('seeder'); |
|
| 291 | 291 | |
| 292 | - $this->seeder->call($name); |
|
| 293 | - } |
|
| 292 | + $this->seeder->call($name); |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - //-------------------------------------------------------------------- |
|
| 295 | + //-------------------------------------------------------------------- |
|
| 296 | 296 | |
| 297 | 297 | } |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | { |
| 37 | 37 | |
| 38 | 38 | protected $descriptions = [ |
| 39 | - 'migrate' => ['migrate [$to]', 'Runs the migrations up or down until schema at version \$to'], |
|
| 40 | - 'quietMigrate' => ['quiteMigrate [$to]', 'Same as migrate but without any feedback.'], |
|
| 41 | - 'refresh' => ['refresh', 'Runs migrations back to version 0 (uninstall) and then back to the most recent migration.'], |
|
| 39 | + 'migrate' => ['migrate [$to]', 'Runs the migrations up or down until schema at version \$to'], |
|
| 40 | + 'quietMigrate' => ['quiteMigrate [$to]', 'Same as migrate but without any feedback.'], |
|
| 41 | + 'refresh' => ['refresh', 'Runs migrations back to version 0 (uninstall) and then back to the most recent migration.'], |
|
| 42 | 42 | 'newMigration' => ['newMigration [$name]', 'Creates a new migration file.'], |
| 43 | - 'seed' => ['seed [$name]', 'Runs the named database seeder.'] |
|
| 43 | + 'seed' => ['seed [$name]', 'Runs the named database seeder.'] |
|
| 44 | 44 | ]; |
| 45 | 45 | |
| 46 | 46 | protected $long_descriptions = [ |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @param bool $silent If TRUE, will NOT display any prompts for verification. |
| 70 | 70 | * @return bool|void |
| 71 | 71 | */ |
| 72 | - public function migrate($type=null, $to = null, $silent = false) |
|
| 72 | + public function migrate($type = null, $to = null, $silent = false) |
|
| 73 | 73 | { |
| 74 | 74 | $this->load->library('migration'); |
| 75 | 75 | |
@@ -90,11 +90,11 @@ discard block |
||
| 90 | 90 | $groups = array_keys($groups); |
| 91 | 91 | |
| 92 | 92 | // If it's not in the groups list, then assume it's a module. |
| 93 | - if (! in_array($type, $groups)) |
|
| 93 | + if ( ! in_array($type, $groups)) |
|
| 94 | 94 | { |
| 95 | 95 | if (strpos($type, 'mod:') !== 0) |
| 96 | 96 | { |
| 97 | - $type = 'mod:'. $type; |
|
| 97 | + $type = 'mod:'.$type; |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | $current = $this->migration->get_version($type); |
| 112 | 112 | |
| 113 | 113 | // Already at the desired version? |
| 114 | - if ((! is_null($to) && $current == $to) OR (is_null($to) && $current == $latest)) |
|
| 114 | + if (( ! is_null($to) && $current == $to) OR (is_null($to) && $current == $latest)) |
|
| 115 | 115 | { |
| 116 | 116 | return $silent ? true : CLI::write("\tDatabase is already at the desired version ({$current})", 'yellow'); |
| 117 | 117 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | // to the latest version. |
| 123 | 123 | if (is_null($to)) { |
| 124 | 124 | // If we're in silent mode, don't prompt, just go to the latest... |
| 125 | - if (! $silent) { |
|
| 125 | + if ( ! $silent) { |
|
| 126 | 126 | $go_ahead = CLI::prompt('Migrate to the latest available version?', array('y', 'n')); |
| 127 | 127 | |
| 128 | 128 | if ($go_ahead == 'n') { |
@@ -130,17 +130,16 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - if (! $this->migration->latest($type)) { |
|
| 134 | - return CLI::error("\n\tERROR: " . $this->migration->error_string() . "\n"); |
|
| 133 | + if ( ! $this->migration->latest($type)) { |
|
| 134 | + return CLI::error("\n\tERROR: ".$this->migration->error_string()."\n"); |
|
| 135 | 135 | } |
| 136 | 136 | } else { |
| 137 | 137 | if ($this->migration->version($type, $to) === false) { |
| 138 | - return CLI::error("\n\tERROR: " . $this->migration->error_string() . "\n"); |
|
| 138 | + return CLI::error("\n\tERROR: ".$this->migration->error_string()."\n"); |
|
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - return $silent ? true : |
|
| 143 | - CLI::write("\n\tSuccessfully migrated database from version {$current} to {$target}.\n", 'green'); |
|
| 142 | + return $silent ? true : CLI::write("\n\tSuccessfully migrated database from version {$current} to {$target}.\n", 'green'); |
|
| 144 | 143 | } |
| 145 | 144 | |
| 146 | 145 | //-------------------------------------------------------------------- |
@@ -154,7 +153,7 @@ discard block |
||
| 154 | 153 | * @param null $to |
| 155 | 154 | * @return bool|void |
| 156 | 155 | */ |
| 157 | - public function quietMigrate($type='app', $to = null) |
|
| 156 | + public function quietMigrate($type = 'app', $to = null) |
|
| 158 | 157 | { |
| 159 | 158 | return $this->migrate($type, $to, true); |
| 160 | 159 | } |
@@ -168,7 +167,7 @@ discard block |
||
| 168 | 167 | * @param string $type The group or module to refresh. |
| 169 | 168 | * @return mixed |
| 170 | 169 | */ |
| 171 | - public function refresh($type=null) |
|
| 170 | + public function refresh($type = null) |
|
| 172 | 171 | { |
| 173 | 172 | $this->load->library('migration'); |
| 174 | 173 | |
@@ -183,13 +182,13 @@ discard block |
||
| 183 | 182 | } |
| 184 | 183 | |
| 185 | 184 | if ($this->migration->version($type, 0) === false) { |
| 186 | - return CLI::error("\tERROR: " . $this->migration->error_string()); |
|
| 185 | + return CLI::error("\tERROR: ".$this->migration->error_string()); |
|
| 187 | 186 | } |
| 188 | 187 | |
| 189 | 188 | CLI::write(CLI::color("\tCleared the database.", 'green')); |
| 190 | 189 | |
| 191 | 190 | if ($this->migration->latest($type) === false) { |
| 192 | - return CLI::error("\tERROR: " . $this->migration->error_string()); |
|
| 191 | + return CLI::error("\tERROR: ".$this->migration->error_string()); |
|
| 193 | 192 | } |
| 194 | 193 | |
| 195 | 194 | CLI::write("\tRe-installed the database to the latest migration.", 'green'); |
@@ -217,23 +216,23 @@ discard block |
||
| 217 | 216 | $path = $this->migration->determine_migration_path($type); |
| 218 | 217 | |
| 219 | 218 | // Does the alias path exist in our config? |
| 220 | - if (! $path) { |
|
| 219 | + if ( ! $path) { |
|
| 221 | 220 | return CLI::error("\tThe migration path for '{$type}' does not exist.'"); |
| 222 | 221 | } |
| 223 | 222 | |
| 224 | 223 | // Does the path really exist? |
| 225 | - if (! is_dir($path)) { |
|
| 224 | + if ( ! is_dir($path)) { |
|
| 226 | 225 | return CLI::error("\tThe path for '{$type}' is not a directory."); |
| 227 | 226 | } |
| 228 | 227 | |
| 229 | 228 | // Is the folder writeable? |
| 230 | - if (! is_writeable($path)) { |
|
| 229 | + if ( ! is_writeable($path)) { |
|
| 231 | 230 | return CLI::error("\tThe folder for '{$type}' migrations is not writeable."); |
| 232 | 231 | } |
| 233 | 232 | |
| 234 | 233 | $file = $this->migration->make_name($name); |
| 235 | 234 | |
| 236 | - $path = rtrim($path, '/') .'/'. $file; |
|
| 235 | + $path = rtrim($path, '/').'/'.$file; |
|
| 237 | 236 | |
| 238 | 237 | $contents = <<<EOT |
| 239 | 238 | <?php |
@@ -269,7 +268,7 @@ discard block |
||
| 269 | 268 | $this->load->helper('file'); |
| 270 | 269 | |
| 271 | 270 | if (write_file($path, $contents)) { |
| 272 | - return CLI::write("\tNew migration created: " . CLI::color($file, 'yellow'), 'green'); |
|
| 271 | + return CLI::write("\tNew migration created: ".CLI::color($file, 'yellow'), 'green'); |
|
| 273 | 272 | } |
| 274 | 273 | |
| 275 | 274 | return CLI::error("\tUnkown error trying to create migration: {$file}", 'red'); |
@@ -39,92 +39,92 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class Seeder { |
| 41 | 41 | |
| 42 | - public $error_string = ''; |
|
| 42 | + public $error_string = ''; |
|
| 43 | 43 | |
| 44 | - protected $ci; |
|
| 44 | + protected $ci; |
|
| 45 | 45 | |
| 46 | - protected $is_cli = false; |
|
| 46 | + protected $is_cli = false; |
|
| 47 | 47 | |
| 48 | - protected $db; |
|
| 49 | - protected $dbforge; |
|
| 48 | + protected $db; |
|
| 49 | + protected $dbforge; |
|
| 50 | 50 | |
| 51 | - //-------------------------------------------------------------------- |
|
| 51 | + //-------------------------------------------------------------------- |
|
| 52 | 52 | |
| 53 | - public function __construct () |
|
| 54 | - { |
|
| 55 | - $this->ci =& get_instance(); |
|
| 53 | + public function __construct () |
|
| 54 | + { |
|
| 55 | + $this->ci =& get_instance(); |
|
| 56 | 56 | |
| 57 | - $this->is_cli = $this->ci->input->is_cli_request(); |
|
| 57 | + $this->is_cli = $this->ci->input->is_cli_request(); |
|
| 58 | 58 | |
| 59 | - if ($this->is_cli) |
|
| 60 | - { |
|
| 61 | - $cli = new CLI(); |
|
| 62 | - $cli::_init(); |
|
| 63 | - } |
|
| 59 | + if ($this->is_cli) |
|
| 60 | + { |
|
| 61 | + $cli = new CLI(); |
|
| 62 | + $cli::_init(); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - $this->ci->load->dbforge(); |
|
| 65 | + $this->ci->load->dbforge(); |
|
| 66 | 66 | |
| 67 | - // Setup some convenience vars. |
|
| 68 | - $this->db =& $this->ci->db; |
|
| 69 | - $this->dbforge =& $this->ci->dbforge; |
|
| 70 | - } |
|
| 67 | + // Setup some convenience vars. |
|
| 68 | + $this->db =& $this->ci->db; |
|
| 69 | + $this->dbforge =& $this->ci->dbforge; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - //-------------------------------------------------------------------- |
|
| 72 | + //-------------------------------------------------------------------- |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Run the database seeds. It's where the magic happens. |
|
| 77 | - * This method MUST be overridden by child classes. |
|
| 78 | - */ |
|
| 79 | - public function run () |
|
| 80 | - { |
|
| 75 | + /** |
|
| 76 | + * Run the database seeds. It's where the magic happens. |
|
| 77 | + * This method MUST be overridden by child classes. |
|
| 78 | + */ |
|
| 79 | + public function run () |
|
| 80 | + { |
|
| 81 | 81 | |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - //-------------------------------------------------------------------- |
|
| 84 | + //-------------------------------------------------------------------- |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Loads the class file and calls the run() method |
|
| 88 | - * on the class. |
|
| 89 | - * |
|
| 90 | - * @param $class |
|
| 91 | - */ |
|
| 92 | - public function call ($class) |
|
| 93 | - { |
|
| 94 | - if (empty($class)) |
|
| 95 | - { |
|
| 96 | - // Ask the user... |
|
| 97 | - $class = trim( CLI::prompt("Seeder name") ); |
|
| 86 | + /** |
|
| 87 | + * Loads the class file and calls the run() method |
|
| 88 | + * on the class. |
|
| 89 | + * |
|
| 90 | + * @param $class |
|
| 91 | + */ |
|
| 92 | + public function call ($class) |
|
| 93 | + { |
|
| 94 | + if (empty($class)) |
|
| 95 | + { |
|
| 96 | + // Ask the user... |
|
| 97 | + $class = trim( CLI::prompt("Seeder name") ); |
|
| 98 | 98 | |
| 99 | - if (empty($class)) { |
|
| 100 | - return CLI::error("\tNo Seeder was specified."); |
|
| 101 | - } |
|
| 102 | - } |
|
| 99 | + if (empty($class)) { |
|
| 100 | + return CLI::error("\tNo Seeder was specified."); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $path = APPPATH .'database/seeds/'. str_replace('.php', '', $class) .'.php'; |
|
| 104 | + $path = APPPATH .'database/seeds/'. str_replace('.php', '', $class) .'.php'; |
|
| 105 | 105 | |
| 106 | - if ( ! is_file($path)) |
|
| 107 | - { |
|
| 108 | - return CLI::error("\tUnable to find seed class: ". $class); |
|
| 109 | - } |
|
| 106 | + if ( ! is_file($path)) |
|
| 107 | + { |
|
| 108 | + return CLI::error("\tUnable to find seed class: ". $class); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - try { |
|
| 112 | - require $path; |
|
| 111 | + try { |
|
| 112 | + require $path; |
|
| 113 | 113 | |
| 114 | - $seeder = new $class(); |
|
| 114 | + $seeder = new $class(); |
|
| 115 | 115 | |
| 116 | - $seeder->run(); |
|
| 116 | + $seeder->run(); |
|
| 117 | 117 | |
| 118 | - unset($seeder); |
|
| 119 | - } |
|
| 120 | - catch (\Exception $e) |
|
| 121 | - { |
|
| 122 | - show_error($e->getMessage(), $e->getCode()); |
|
| 123 | - } |
|
| 118 | + unset($seeder); |
|
| 119 | + } |
|
| 120 | + catch (\Exception $e) |
|
| 121 | + { |
|
| 122 | + show_error($e->getMessage(), $e->getCode()); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - return Cli::write("\tSeeded: $class", 'green'); |
|
| 126 | - } |
|
| 125 | + return Cli::write("\tSeeded: $class", 'green'); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - //-------------------------------------------------------------------- |
|
| 128 | + //-------------------------------------------------------------------- |
|
| 129 | 129 | |
| 130 | 130 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | class Seeder { |
| 41 | 41 | |
| 42 | - public $error_string = ''; |
|
| 42 | + public $error_string = ''; |
|
| 43 | 43 | |
| 44 | 44 | protected $ci; |
| 45 | 45 | |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | //-------------------------------------------------------------------- |
| 52 | 52 | |
| 53 | - public function __construct () |
|
| 53 | + public function __construct() |
|
| 54 | 54 | { |
| 55 | - $this->ci =& get_instance(); |
|
| 55 | + $this->ci = & get_instance(); |
|
| 56 | 56 | |
| 57 | 57 | $this->is_cli = $this->ci->input->is_cli_request(); |
| 58 | 58 | |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | $this->ci->load->dbforge(); |
| 66 | 66 | |
| 67 | 67 | // Setup some convenience vars. |
| 68 | - $this->db =& $this->ci->db; |
|
| 69 | - $this->dbforge =& $this->ci->dbforge; |
|
| 68 | + $this->db = & $this->ci->db; |
|
| 69 | + $this->dbforge = & $this->ci->dbforge; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | //-------------------------------------------------------------------- |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * Run the database seeds. It's where the magic happens. |
| 77 | 77 | * This method MUST be overridden by child classes. |
| 78 | 78 | */ |
| 79 | - public function run () |
|
| 79 | + public function run() |
|
| 80 | 80 | { |
| 81 | 81 | |
| 82 | 82 | } |
@@ -89,23 +89,23 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @param $class |
| 91 | 91 | */ |
| 92 | - public function call ($class) |
|
| 92 | + public function call($class) |
|
| 93 | 93 | { |
| 94 | 94 | if (empty($class)) |
| 95 | 95 | { |
| 96 | 96 | // Ask the user... |
| 97 | - $class = trim( CLI::prompt("Seeder name") ); |
|
| 97 | + $class = trim(CLI::prompt("Seeder name")); |
|
| 98 | 98 | |
| 99 | 99 | if (empty($class)) { |
| 100 | 100 | return CLI::error("\tNo Seeder was specified."); |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - $path = APPPATH .'database/seeds/'. str_replace('.php', '', $class) .'.php'; |
|
| 104 | + $path = APPPATH.'database/seeds/'.str_replace('.php', '', $class).'.php'; |
|
| 105 | 105 | |
| 106 | 106 | if ( ! is_file($path)) |
| 107 | 107 | { |
| 108 | - return CLI::error("\tUnable to find seed class: ". $class); |
|
| 108 | + return CLI::error("\tUnable to find seed class: ".$class); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | try { |
@@ -116,8 +116,7 @@ |
||
| 116 | 116 | $seeder->run(); |
| 117 | 117 | |
| 118 | 118 | unset($seeder); |
| 119 | - } |
|
| 120 | - catch (\Exception $e) |
|
| 119 | + } catch (\Exception $e) |
|
| 121 | 120 | { |
| 122 | 121 | show_error($e->getMessage(), $e->getCode()); |
| 123 | 122 | } |
@@ -57,8 +57,8 @@ |
||
| 57 | 57 | | if realpath cannot find/read the folder. |
| 58 | 58 | */ |
| 59 | 59 | $config['docs.folders'] = [ |
| 60 | - 'application' => APPPATH .'docs', |
|
| 61 | - 'developer' => APPPATH .'../myth/_docs_src' |
|
| 60 | + 'application' => APPPATH .'docs', |
|
| 61 | + 'developer' => APPPATH .'../myth/_docs_src' |
|
| 62 | 62 | ]; |
| 63 | 63 | |
| 64 | 64 | /* |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | | if realpath cannot find/read the folder. |
| 58 | 58 | */ |
| 59 | 59 | $config['docs.folders'] = [ |
| 60 | - 'application' => APPPATH .'docs', |
|
| 61 | - 'developer' => APPPATH .'../myth/_docs_src' |
|
| 60 | + 'application' => APPPATH.'docs', |
|
| 61 | + 'developer' => APPPATH.'../myth/_docs_src' |
|
| 62 | 62 | ]; |
| 63 | 63 | |
| 64 | 64 | /* |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | | If you change it, ensure that it includes the period (.). |
| 90 | 90 | */ |
| 91 | 91 | |
| 92 | -$config['docs.extension'] = '.md'; |
|
| 92 | +$config['docs.extension'] = '.md'; |
|
| 93 | 93 | |
| 94 | 94 | /* |
| 95 | 95 | * If true, the 'developer' docs will be displayed in environments other than |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | $this->load->helper('form'); |
| 76 | 76 | $this->load->helper('language'); |
| 77 | 77 | |
| 78 | - $this->docbuilder = new \Myth\Docs\Builder( array('apppath' => APPPATH) ); |
|
| 78 | + $this->docbuilder = new \Myth\Docs\Builder(array('apppath' => APPPATH)); |
|
| 79 | 79 | |
| 80 | - $formatter = function ($str) { |
|
| 80 | + $formatter = function($str) { |
|
| 81 | 81 | $converter = new \League\CommonMark\CommonMarkConverter(); |
| 82 | 82 | return $converter->convertToHtml($str); |
| 83 | 83 | }; |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | { |
| 163 | 163 | // Is displaying docs permitted for this environment? |
| 164 | 164 | if (config_item('docs.permitted_environments') |
| 165 | - && !in_array(ENVIRONMENT, config_item('docs.permitted_environments')) |
|
| 165 | + && ! in_array(ENVIRONMENT, config_item('docs.permitted_environments')) |
|
| 166 | 166 | ) { |
| 167 | 167 | $this->setMessage(lang('docs_env_disabled'), 'error'); |
| 168 | 168 | redirect(); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $this->current_group = false; |
| 178 | 178 | } // Are we allowed to show developer docs in this environment? |
| 179 | 179 | elseif ($current_group == 'developer' |
| 180 | - && !$this->showDevDocs |
|
| 180 | + && ! $this->showDevDocs |
|
| 181 | 181 | && ENVIRONMENT != 'development' |
| 182 | 182 | ) { |
| 183 | 183 | if ($this->showAppDocs) { |
@@ -216,8 +216,8 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | // If nothing left, then assign the default group and redirect to |
| 218 | 218 | // a page we can do something with... |
| 219 | - if (!count($segments)) { |
|
| 220 | - redirect('docs/' . config_item('docs.default_group')); |
|
| 219 | + if ( ! count($segments)) { |
|
| 220 | + redirect('docs/'.config_item('docs.default_group')); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // Do we have a group specified? Bonfire Docs requires that a group |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | $data = []; |
| 249 | 249 | |
| 250 | 250 | // Set the remaining data for the view |
| 251 | - $data['docsDir'] = 'docs/' . $this->current_group . '/'; |
|
| 251 | + $data['docsDir'] = 'docs/'.$this->current_group.'/'; |
|
| 252 | 252 | $data['docsExt'] = config_item('docs.extension'); |
| 253 | 253 | |
| 254 | 254 | $data['docMap'] = $this->docbuilder->buildDocumentMap($content); |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | */ |
| 268 | 268 | private function buildTOC() |
| 269 | 269 | { |
| 270 | - $folder = $this->doc_folders[$this->current_group] . '/'; |
|
| 270 | + $folder = $this->doc_folders[$this->current_group].'/'; |
|
| 271 | 271 | |
| 272 | 272 | $map = $this->docbuilder->buildTOC($folder); |
| 273 | 273 | |
@@ -291,11 +291,11 @@ discard block |
||
| 291 | 291 | $docs_modules = array(); |
| 292 | 292 | foreach (\Bonfire\Modules::list_modules() as $module) { |
| 293 | 293 | $ignored_folders = array(); |
| 294 | - $path = \Bonfire\Modules::path($module) . $this->docsDir; |
|
| 294 | + $path = \Bonfire\Modules::path($module).$this->docsDir; |
|
| 295 | 295 | |
| 296 | 296 | // If these are developer docs, add the folder to the path. |
| 297 | 297 | if ($this->current_group == $this->docsTypeBf) { |
| 298 | - $path .= '/' . $this->docsTypeBf; |
|
| 298 | + $path .= '/'.$this->docsTypeBf; |
|
| 299 | 299 | } // For Application docs, ignore the 'developers' folder. |
| 300 | 300 | else { |
| 301 | 301 | $ignored_folders[] = $this->docsTypeBf; |
@@ -33,284 +33,284 @@ |
||
| 33 | 33 | class Docs extends \Myth\Controllers\ThemedController |
| 34 | 34 | { |
| 35 | 35 | |
| 36 | - protected $ignoreFiles = array('_404.md'); |
|
| 36 | + protected $ignoreFiles = array('_404.md'); |
|
| 37 | 37 | |
| 38 | - protected $tocFile; |
|
| 38 | + protected $tocFile; |
|
| 39 | 39 | |
| 40 | - protected $doc_folders = []; |
|
| 40 | + protected $doc_folders = []; |
|
| 41 | 41 | |
| 42 | - protected $current_group = null; |
|
| 42 | + protected $current_group = null; |
|
| 43 | 43 | |
| 44 | - protected $current_path = null; |
|
| 44 | + protected $current_path = null; |
|
| 45 | 45 | |
| 46 | - private $showAppDocs; |
|
| 46 | + private $showAppDocs; |
|
| 47 | 47 | |
| 48 | - private $showDevDocs; |
|
| 48 | + private $showDevDocs; |
|
| 49 | 49 | |
| 50 | - protected $theme = 'docs'; |
|
| 50 | + protected $theme = 'docs'; |
|
| 51 | 51 | |
| 52 | - protected $auto_escape = false; |
|
| 52 | + protected $auto_escape = false; |
|
| 53 | 53 | |
| 54 | - //-------------------------------------------------------------------------- |
|
| 54 | + //-------------------------------------------------------------------------- |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Constructor |
|
| 58 | - * |
|
| 59 | - * @return \Docs |
|
| 60 | - */ |
|
| 61 | - public function __construct() |
|
| 62 | - { |
|
| 63 | - parent::__construct(); |
|
| 56 | + /** |
|
| 57 | + * Constructor |
|
| 58 | + * |
|
| 59 | + * @return \Docs |
|
| 60 | + */ |
|
| 61 | + public function __construct() |
|
| 62 | + { |
|
| 63 | + parent::__construct(); |
|
| 64 | 64 | |
| 65 | - $this->load->config('docs'); |
|
| 66 | - $this->lang->load('docs'); |
|
| 65 | + $this->load->config('docs'); |
|
| 66 | + $this->lang->load('docs'); |
|
| 67 | 67 | |
| 68 | - // Save our folders |
|
| 69 | - $this->doc_folders = config_item('docs.folders'); |
|
| 68 | + // Save our folders |
|
| 69 | + $this->doc_folders = config_item('docs.folders'); |
|
| 70 | 70 | |
| 71 | - list($this->current_group, $this->current_path) = $this->determineFromURL(); |
|
| 71 | + list($this->current_group, $this->current_path) = $this->determineFromURL(); |
|
| 72 | 72 | |
| 73 | - $this->determineVisibleGroups($this->current_group, $this->current_path); |
|
| 73 | + $this->determineVisibleGroups($this->current_group, $this->current_path); |
|
| 74 | 74 | |
| 75 | - $this->load->helper('form'); |
|
| 76 | - $this->load->helper('language'); |
|
| 75 | + $this->load->helper('form'); |
|
| 76 | + $this->load->helper('language'); |
|
| 77 | 77 | |
| 78 | - $this->docbuilder = new \Myth\Docs\Builder( array('apppath' => APPPATH) ); |
|
| 78 | + $this->docbuilder = new \Myth\Docs\Builder( array('apppath' => APPPATH) ); |
|
| 79 | 79 | |
| 80 | - $formatter = function ($str) { |
|
| 81 | - $converter = new \League\CommonMark\CommonMarkConverter(); |
|
| 82 | - return $converter->convertToHtml($str); |
|
| 83 | - }; |
|
| 84 | - $this->docbuilder->registerFormatter($formatter, true); |
|
| 85 | - } |
|
| 80 | + $formatter = function ($str) { |
|
| 81 | + $converter = new \League\CommonMark\CommonMarkConverter(); |
|
| 82 | + return $converter->convertToHtml($str); |
|
| 83 | + }; |
|
| 84 | + $this->docbuilder->registerFormatter($formatter, true); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - //-------------------------------------------------------------------- |
|
| 87 | + //-------------------------------------------------------------------- |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Display the list of documents available and the current document |
|
| 91 | - * |
|
| 92 | - * @return void |
|
| 93 | - */ |
|
| 94 | - public function index() |
|
| 95 | - { |
|
| 96 | - $data = array(); |
|
| 89 | + /** |
|
| 90 | + * Display the list of documents available and the current document |
|
| 91 | + * |
|
| 92 | + * @return void |
|
| 93 | + */ |
|
| 94 | + public function index() |
|
| 95 | + { |
|
| 96 | + $data = array(); |
|
| 97 | 97 | |
| 98 | - // Make sure the builder knows where to look |
|
| 99 | - foreach ($this->doc_folders as $alias => $folder) { |
|
| 100 | - $this->docbuilder->addDocFolder($alias, $folder); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - try { |
|
| 104 | - $content = $this->docbuilder->readPage($this->current_path, $this->current_group); |
|
| 105 | - $content = $this->docbuilder->postProcess($content, site_url(), current_url()); |
|
| 106 | - |
|
| 107 | - $data['sidebar'] = $this->buildSidebar($content); |
|
| 108 | - $data['toc'] = $this->buildTOC(); |
|
| 109 | - $data['content'] = $content; |
|
| 110 | - $data['page_title'] = $this->docbuilder->pageTitle(); |
|
| 111 | - } catch (Exception $e) { |
|
| 112 | - $this->setMessage($e->getMessage(), 'warning'); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $this->render($data, config_item('docs.cache_time')); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - //-------------------------------------------------------------------- |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Display search results and handles the search itself. |
|
| 122 | - * |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - public function search() |
|
| 126 | - { |
|
| 127 | - $this->benchmark->mark('search_start'); |
|
| 128 | - $this->docsearch = new \Myth\Docs\Search(); |
|
| 129 | - $this->load->helper('markdown_extended'); |
|
| 130 | - $this->docsearch->registerFormatter('MarkdownExtended', true); |
|
| 131 | - |
|
| 132 | - $data = array(); |
|
| 133 | - |
|
| 134 | - $terms = $this->input->post('search_terms'); |
|
| 135 | - |
|
| 136 | - if ($terms) { |
|
| 137 | - $search_folders = $this->doc_folders; |
|
| 138 | - |
|
| 139 | - $data['results'] = $this->docsearch->search($terms, $search_folders); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $this->benchmark->mark('search_end'); |
|
| 143 | - |
|
| 144 | - $data['search_time'] = $this->benchmark->elapsed_time('search_start', 'search_end'); |
|
| 145 | - $data['search_terms'] = $terms; |
|
| 146 | - $data['page_title'] = 'Search Results'; |
|
| 147 | - |
|
| 148 | - $this->render($data); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - //-------------------------------------------------------------------------- |
|
| 152 | - // Private Methods |
|
| 153 | - //-------------------------------------------------------------------------- |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Determines which groups are allowed to be viewed by the current system |
|
| 157 | - * and the user/environment. |
|
| 158 | - * |
|
| 159 | - * todo Allow docs groups to be shown/hidden per-environment, using assoc-array for permitted environments |
|
| 160 | - */ |
|
| 161 | - private function determineVisibleGroups($current_group, $current_path) |
|
| 162 | - { |
|
| 163 | - // Is displaying docs permitted for this environment? |
|
| 164 | - if (config_item('docs.permitted_environments') |
|
| 165 | - && !in_array(ENVIRONMENT, config_item('docs.permitted_environments')) |
|
| 166 | - ) { |
|
| 167 | - $this->setMessage(lang('docs_env_disabled'), 'danger'); |
|
| 168 | - redirect(); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - $this->showAppDocs = config_item('docs.show_app_docs'); |
|
| 172 | - $this->showDevDocs = config_item('docs.show_dev_docs'); |
|
| 173 | - $this->tocFile = config_item('docs.toc_file') ?: '_toc.ini'; |
|
| 174 | - |
|
| 175 | - // Make sure we can still get to the search method. |
|
| 176 | - if ($current_group == 'search') { |
|
| 177 | - $this->current_group = false; |
|
| 178 | - } // Are we allowed to show developer docs in this environment? |
|
| 179 | - elseif ($current_group == 'developer' |
|
| 180 | - && !$this->showDevDocs |
|
| 181 | - && ENVIRONMENT != 'development' |
|
| 182 | - ) { |
|
| 183 | - if ($this->showAppDocs) { |
|
| 184 | - $this->setMessage(lang('docs_not_allowed_dev'), 'warning'); |
|
| 185 | - |
|
| 186 | - redirect('docs/application'); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - show_error(lang('docs_not_allowed')); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - //-------------------------------------------------------------------- |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Determines the current doc group and file path from the current URL. |
|
| 197 | - * |
|
| 198 | - * Returns an array with the group and file path in the 0 and 1 positions, respectively. |
|
| 199 | - * |
|
| 200 | - * @return array |
|
| 201 | - */ |
|
| 202 | - private function determineFromURL() |
|
| 203 | - { |
|
| 204 | - $return = [ |
|
| 205 | - '', // Group |
|
| 206 | - '', // File Path |
|
| 207 | - ]; |
|
| 208 | - |
|
| 209 | - $segments = $this->uri->segment_array(); |
|
| 210 | - |
|
| 211 | - // Remove the 'docs' from the array |
|
| 212 | - // for now, we assume this is the first one |
|
| 213 | - // since that is how Bonfire is setup to show docs |
|
| 214 | - // @todo Make it so the path can be modified and this still works. |
|
| 215 | - array_shift($segments); |
|
| 216 | - |
|
| 217 | - // If nothing left, then assign the default group and redirect to |
|
| 218 | - // a page we can do something with... |
|
| 219 | - if (!count($segments)) { |
|
| 220 | - redirect('docs/' . config_item('docs.default_group')); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // Do we have a group specified? Bonfire Docs requires that a group |
|
| 224 | - // be part of the URI so it should be the first element on the array. |
|
| 225 | - $return[0] = array_shift($segments); |
|
| 226 | - |
|
| 227 | - // If there's any more left, then join them together and they'll |
|
| 228 | - // form the path to the file. This will allow for subfolders with the |
|
| 229 | - // docs folder itself. |
|
| 230 | - $return[1] = count($segments) ? implode('/', $segments) : 'index'; |
|
| 231 | - |
|
| 232 | - return $return; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - //-------------------------------------------------------------------- |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Builds a TOC for the sidebar out of files found in the following folders: |
|
| 239 | - * - application/docs |
|
| 240 | - * - bonfire/docs |
|
| 241 | - * - {module}/docs |
|
| 242 | - * |
|
| 243 | - * @param $content The HTML generated for the page content. |
|
| 244 | - * @return string The HTML for the sidebar. |
|
| 245 | - */ |
|
| 246 | - private function buildSidebar(&$content) |
|
| 247 | - { |
|
| 248 | - $data = []; |
|
| 249 | - |
|
| 250 | - // Set the remaining data for the view |
|
| 251 | - $data['docsDir'] = 'docs/' . $this->current_group . '/'; |
|
| 252 | - $data['docsExt'] = config_item('docs.extension'); |
|
| 253 | - |
|
| 254 | - $data['docMap'] = $this->docbuilder->buildDocumentMap($content); |
|
| 255 | - |
|
| 256 | - return $this->docbuilder->postProcess( |
|
| 257 | - $this->load->view('docs/_document_map', $data, true), |
|
| 258 | - site_url(), |
|
| 259 | - current_url() |
|
| 260 | - ); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - //-------------------------------------------------------------------- |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Builds out the nested lists of items that are needed |
|
| 267 | - */ |
|
| 268 | - private function buildTOC() |
|
| 269 | - { |
|
| 270 | - $folder = $this->doc_folders[$this->current_group] . '/'; |
|
| 271 | - |
|
| 272 | - $map = $this->docbuilder->buildTOC($folder); |
|
| 273 | - |
|
| 274 | - return $this->docbuilder->postProcess( |
|
| 275 | - $this->load->view('docs/_toc', ['map' => $map], true), |
|
| 276 | - site_url(), |
|
| 277 | - current_url() |
|
| 278 | - ); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - //-------------------------------------------------------------------- |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Checks all modules to see if they include docs and prepares their doc |
|
| 285 | - * information for use in the sidebar. |
|
| 286 | - * |
|
| 287 | - * @return array |
|
| 288 | - */ |
|
| 289 | - private function get_module_docs() |
|
| 290 | - { |
|
| 291 | - $docs_modules = array(); |
|
| 292 | - foreach (\Bonfire\Modules::list_modules() as $module) { |
|
| 293 | - $ignored_folders = array(); |
|
| 294 | - $path = \Bonfire\Modules::path($module) . $this->docsDir; |
|
| 295 | - |
|
| 296 | - // If these are developer docs, add the folder to the path. |
|
| 297 | - if ($this->current_group == $this->docsTypeBf) { |
|
| 298 | - $path .= '/' . $this->docsTypeBf; |
|
| 299 | - } // For Application docs, ignore the 'developers' folder. |
|
| 300 | - else { |
|
| 301 | - $ignored_folders[] = $this->docsTypeBf; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if (is_dir($path)) { |
|
| 305 | - $files = $this->get_folder_files($path, $module, $ignored_folders); |
|
| 306 | - if (is_array($files) && count($files)) { |
|
| 307 | - $docs_modules[$module] = $files; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - return $docs_modules; |
|
| 313 | - } |
|
| 314 | - //-------------------------------------------------------------------- |
|
| 98 | + // Make sure the builder knows where to look |
|
| 99 | + foreach ($this->doc_folders as $alias => $folder) { |
|
| 100 | + $this->docbuilder->addDocFolder($alias, $folder); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + try { |
|
| 104 | + $content = $this->docbuilder->readPage($this->current_path, $this->current_group); |
|
| 105 | + $content = $this->docbuilder->postProcess($content, site_url(), current_url()); |
|
| 106 | + |
|
| 107 | + $data['sidebar'] = $this->buildSidebar($content); |
|
| 108 | + $data['toc'] = $this->buildTOC(); |
|
| 109 | + $data['content'] = $content; |
|
| 110 | + $data['page_title'] = $this->docbuilder->pageTitle(); |
|
| 111 | + } catch (Exception $e) { |
|
| 112 | + $this->setMessage($e->getMessage(), 'warning'); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $this->render($data, config_item('docs.cache_time')); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + //-------------------------------------------------------------------- |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Display search results and handles the search itself. |
|
| 122 | + * |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + public function search() |
|
| 126 | + { |
|
| 127 | + $this->benchmark->mark('search_start'); |
|
| 128 | + $this->docsearch = new \Myth\Docs\Search(); |
|
| 129 | + $this->load->helper('markdown_extended'); |
|
| 130 | + $this->docsearch->registerFormatter('MarkdownExtended', true); |
|
| 131 | + |
|
| 132 | + $data = array(); |
|
| 133 | + |
|
| 134 | + $terms = $this->input->post('search_terms'); |
|
| 135 | + |
|
| 136 | + if ($terms) { |
|
| 137 | + $search_folders = $this->doc_folders; |
|
| 138 | + |
|
| 139 | + $data['results'] = $this->docsearch->search($terms, $search_folders); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $this->benchmark->mark('search_end'); |
|
| 143 | + |
|
| 144 | + $data['search_time'] = $this->benchmark->elapsed_time('search_start', 'search_end'); |
|
| 145 | + $data['search_terms'] = $terms; |
|
| 146 | + $data['page_title'] = 'Search Results'; |
|
| 147 | + |
|
| 148 | + $this->render($data); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + //-------------------------------------------------------------------------- |
|
| 152 | + // Private Methods |
|
| 153 | + //-------------------------------------------------------------------------- |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Determines which groups are allowed to be viewed by the current system |
|
| 157 | + * and the user/environment. |
|
| 158 | + * |
|
| 159 | + * todo Allow docs groups to be shown/hidden per-environment, using assoc-array for permitted environments |
|
| 160 | + */ |
|
| 161 | + private function determineVisibleGroups($current_group, $current_path) |
|
| 162 | + { |
|
| 163 | + // Is displaying docs permitted for this environment? |
|
| 164 | + if (config_item('docs.permitted_environments') |
|
| 165 | + && !in_array(ENVIRONMENT, config_item('docs.permitted_environments')) |
|
| 166 | + ) { |
|
| 167 | + $this->setMessage(lang('docs_env_disabled'), 'danger'); |
|
| 168 | + redirect(); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + $this->showAppDocs = config_item('docs.show_app_docs'); |
|
| 172 | + $this->showDevDocs = config_item('docs.show_dev_docs'); |
|
| 173 | + $this->tocFile = config_item('docs.toc_file') ?: '_toc.ini'; |
|
| 174 | + |
|
| 175 | + // Make sure we can still get to the search method. |
|
| 176 | + if ($current_group == 'search') { |
|
| 177 | + $this->current_group = false; |
|
| 178 | + } // Are we allowed to show developer docs in this environment? |
|
| 179 | + elseif ($current_group == 'developer' |
|
| 180 | + && !$this->showDevDocs |
|
| 181 | + && ENVIRONMENT != 'development' |
|
| 182 | + ) { |
|
| 183 | + if ($this->showAppDocs) { |
|
| 184 | + $this->setMessage(lang('docs_not_allowed_dev'), 'warning'); |
|
| 185 | + |
|
| 186 | + redirect('docs/application'); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + show_error(lang('docs_not_allowed')); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + //-------------------------------------------------------------------- |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Determines the current doc group and file path from the current URL. |
|
| 197 | + * |
|
| 198 | + * Returns an array with the group and file path in the 0 and 1 positions, respectively. |
|
| 199 | + * |
|
| 200 | + * @return array |
|
| 201 | + */ |
|
| 202 | + private function determineFromURL() |
|
| 203 | + { |
|
| 204 | + $return = [ |
|
| 205 | + '', // Group |
|
| 206 | + '', // File Path |
|
| 207 | + ]; |
|
| 208 | + |
|
| 209 | + $segments = $this->uri->segment_array(); |
|
| 210 | + |
|
| 211 | + // Remove the 'docs' from the array |
|
| 212 | + // for now, we assume this is the first one |
|
| 213 | + // since that is how Bonfire is setup to show docs |
|
| 214 | + // @todo Make it so the path can be modified and this still works. |
|
| 215 | + array_shift($segments); |
|
| 216 | + |
|
| 217 | + // If nothing left, then assign the default group and redirect to |
|
| 218 | + // a page we can do something with... |
|
| 219 | + if (!count($segments)) { |
|
| 220 | + redirect('docs/' . config_item('docs.default_group')); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // Do we have a group specified? Bonfire Docs requires that a group |
|
| 224 | + // be part of the URI so it should be the first element on the array. |
|
| 225 | + $return[0] = array_shift($segments); |
|
| 226 | + |
|
| 227 | + // If there's any more left, then join them together and they'll |
|
| 228 | + // form the path to the file. This will allow for subfolders with the |
|
| 229 | + // docs folder itself. |
|
| 230 | + $return[1] = count($segments) ? implode('/', $segments) : 'index'; |
|
| 231 | + |
|
| 232 | + return $return; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + //-------------------------------------------------------------------- |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Builds a TOC for the sidebar out of files found in the following folders: |
|
| 239 | + * - application/docs |
|
| 240 | + * - bonfire/docs |
|
| 241 | + * - {module}/docs |
|
| 242 | + * |
|
| 243 | + * @param $content The HTML generated for the page content. |
|
| 244 | + * @return string The HTML for the sidebar. |
|
| 245 | + */ |
|
| 246 | + private function buildSidebar(&$content) |
|
| 247 | + { |
|
| 248 | + $data = []; |
|
| 249 | + |
|
| 250 | + // Set the remaining data for the view |
|
| 251 | + $data['docsDir'] = 'docs/' . $this->current_group . '/'; |
|
| 252 | + $data['docsExt'] = config_item('docs.extension'); |
|
| 253 | + |
|
| 254 | + $data['docMap'] = $this->docbuilder->buildDocumentMap($content); |
|
| 255 | + |
|
| 256 | + return $this->docbuilder->postProcess( |
|
| 257 | + $this->load->view('docs/_document_map', $data, true), |
|
| 258 | + site_url(), |
|
| 259 | + current_url() |
|
| 260 | + ); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + //-------------------------------------------------------------------- |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Builds out the nested lists of items that are needed |
|
| 267 | + */ |
|
| 268 | + private function buildTOC() |
|
| 269 | + { |
|
| 270 | + $folder = $this->doc_folders[$this->current_group] . '/'; |
|
| 271 | + |
|
| 272 | + $map = $this->docbuilder->buildTOC($folder); |
|
| 273 | + |
|
| 274 | + return $this->docbuilder->postProcess( |
|
| 275 | + $this->load->view('docs/_toc', ['map' => $map], true), |
|
| 276 | + site_url(), |
|
| 277 | + current_url() |
|
| 278 | + ); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + //-------------------------------------------------------------------- |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Checks all modules to see if they include docs and prepares their doc |
|
| 285 | + * information for use in the sidebar. |
|
| 286 | + * |
|
| 287 | + * @return array |
|
| 288 | + */ |
|
| 289 | + private function get_module_docs() |
|
| 290 | + { |
|
| 291 | + $docs_modules = array(); |
|
| 292 | + foreach (\Bonfire\Modules::list_modules() as $module) { |
|
| 293 | + $ignored_folders = array(); |
|
| 294 | + $path = \Bonfire\Modules::path($module) . $this->docsDir; |
|
| 295 | + |
|
| 296 | + // If these are developer docs, add the folder to the path. |
|
| 297 | + if ($this->current_group == $this->docsTypeBf) { |
|
| 298 | + $path .= '/' . $this->docsTypeBf; |
|
| 299 | + } // For Application docs, ignore the 'developers' folder. |
|
| 300 | + else { |
|
| 301 | + $ignored_folders[] = $this->docsTypeBf; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if (is_dir($path)) { |
|
| 305 | + $files = $this->get_folder_files($path, $module, $ignored_folders); |
|
| 306 | + if (is_array($files) && count($files)) { |
|
| 307 | + $docs_modules[$module] = $files; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + return $docs_modules; |
|
| 313 | + } |
|
| 314 | + //-------------------------------------------------------------------- |
|
| 315 | 315 | |
| 316 | 316 | } |
@@ -7,12 +7,12 @@ discard block |
||
| 7 | 7 | <div class="nav-header"><?php echo $file; ?></div> |
| 8 | 8 | <ul class="nav"> |
| 9 | 9 | <?php foreach ($name as $line => $namer) : ?> |
| 10 | - <li><?php echo anchor($docsDir . str_replace($docsExt, '', $line), $namer); ?></li> |
|
| 10 | + <li><?php echo anchor($docsDir.str_replace($docsExt, '', $line), $namer); ?></li> |
|
| 11 | 11 | <?php endforeach; ?> |
| 12 | 12 | </ul> |
| 13 | 13 | </li> |
| 14 | 14 | <?php else : ?> |
| 15 | - <li><?php echo anchor($docsDir . str_replace($docsExt, '', $file), $name); ?></li> |
|
| 15 | + <li><?php echo anchor($docsDir.str_replace($docsExt, '', $file), $name); ?></li> |
|
| 16 | 16 | <?php endif ?> |
| 17 | 17 | <?php endforeach ?> |
| 18 | 18 | <?php else : ?> |
@@ -29,12 +29,12 @@ discard block |
||
| 29 | 29 | <div class='nav-header'><?php echo $module; ?></div> |
| 30 | 30 | <ul class='nav'> |
| 31 | 31 | <?php foreach ($mod_files as $fileName => $title) : ?> |
| 32 | - <li><?php echo anchor(site_url($docsDir . '/' . str_replace($docsExt, '', $fileName)), ucwords($title)); ?></li> |
|
| 32 | + <li><?php echo anchor(site_url($docsDir.'/'.str_replace($docsExt, '', $fileName)), ucwords($title)); ?></li> |
|
| 33 | 33 | <?php endforeach; ?> |
| 34 | 34 | </ul> |
| 35 | 35 | </li> |
| 36 | 36 | <?php else : ?> |
| 37 | - <li class='parent'><?php echo anchor(site_url($docsDir . '/' . str_replace($docsExt, '', $module)), ucwords(str_replace('_', ' ', $module))); ?></li> |
|
| 37 | + <li class='parent'><?php echo anchor(site_url($docsDir.'/'.str_replace($docsExt, '', $module)), ucwords(str_replace('_', ' ', $module))); ?></li> |
|
| 38 | 38 | <?php endif ?> |
| 39 | 39 | <?php endforeach ?> |
| 40 | 40 | <?php endif ?> |
@@ -11,12 +11,18 @@ discard block |
||
| 11 | 11 | <?php endforeach; ?> |
| 12 | 12 | </ul> |
| 13 | 13 | </li> |
| 14 | - <?php else : ?> |
|
| 15 | - <li><?php echo anchor($docsDir . str_replace($docsExt, '', $file), $name); ?></li> |
|
| 14 | + <?php else { |
|
| 15 | + : ?> |
|
| 16 | + <li><?php echo anchor($docsDir . str_replace($docsExt, '', $file), $name); |
|
| 17 | +} |
|
| 18 | +?></li> |
|
| 16 | 19 | <?php endif ?> |
| 17 | 20 | <?php endforeach ?> |
| 18 | - <?php else : ?> |
|
| 19 | - <p class="text-center"><?php echo lang('docs_not_found'); ?></p> |
|
| 21 | + <?php else { |
|
| 22 | + : ?> |
|
| 23 | + <p class="text-center"><?php echo lang('docs_not_found'); |
|
| 24 | +} |
|
| 25 | +?></p> |
|
| 20 | 26 | <?php endif ?> |
| 21 | 27 | |
| 22 | 28 | <?php if ( ! empty($module_docs) && is_array($module_docs)) : ?> |
@@ -33,8 +39,11 @@ discard block |
||
| 33 | 39 | <?php endforeach; ?> |
| 34 | 40 | </ul> |
| 35 | 41 | </li> |
| 36 | - <?php else : ?> |
|
| 37 | - <li class='parent'><?php echo anchor(site_url($docsDir . '/' . str_replace($docsExt, '', $module)), ucwords(str_replace('_', ' ', $module))); ?></li> |
|
| 42 | + <?php else { |
|
| 43 | + : ?> |
|
| 44 | + <li class='parent'><?php echo anchor(site_url($docsDir . '/' . str_replace($docsExt, '', $module)), ucwords(str_replace('_', ' ', $module))); |
|
| 45 | +} |
|
| 46 | +?></li> |
|
| 38 | 47 | <?php endif ?> |
| 39 | 48 | <?php endforeach ?> |
| 40 | 49 | <?php endif ?> |