1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Modules;
13
14 15 16
17 class ActivateOperation extends \ICanBoogie\Operation
18 {
19 protected function get_controls()
20 {
21 return array
22 (
23 self::CONTROL_PERMISSION => Module::PERMISSION_ADMINISTER
24 )
25
26 + parent::get_controls();
27 }
28
29 protected function validate(\ICanBoogie\Errors $errors)
30 {
31 global $core;
32
33 $install_errors = new \ICanBoogie\Errors;
34
35 foreach ((array) $this->key as $key => $dummy)
36 {
37 try
38 {
39 $core->modules[$key] = true;
40 $module = $core->modules[$key];
41 $install_errors->clear();
42 $rc = $module->is_installed($install_errors);
43
44 if (!$rc || count($install_errors))
45 {
46 $module->install($errors);
47
48 \ICanBoogie\log_success('The module %title was installed.', array('title' => $module->title));
49 }
50
51 $enabled[$key] = true;
52 }
53 catch (\Exception $e)
54 {
55 $core->modules[$key] = false;
56 $errors[] = $e->getMessage();
57 }
58 }
59
60 return !count($errors);
61 }
62
63 protected function process()
64 {
65 global $core;
66
67 $enabled = array_keys($core->modules->enabled_modules_descriptors);
68 $enabled = array_flip($enabled);
69
70 foreach ((array) $this->key as $key => $dummy)
71 {
72 $enabled[$key] = true;
73 }
74
75 $core->vars['enabled_modules'] = array_keys($enabled);
76
77 $this->response->location = \ICanBoogie\Routing\contextualize('/admin/' . (string) $this->module);
78
79 return true;
80 }
81 }