1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
2 require_once('op5/auth/Auth.php');
3 require_once('op5/auth/User_AlwaysAuth.php');
5 class Db_Migrations_Controller
extends Controller
{
6 public function __construct()
8 if (PHP_SAPI
!== "cli") {
9 echo "You may not access this.";
12 parent
::__construct();
13 $this->auto_render
= false;
14 $op5_auth = Op5Auth
::factory(array('session_key' => false));
15 $op5_auth->force_user(new Op5User_AlwaysAuth());
19 * reports from per-report-type tables to all-in-one
21 public function v13_to_v14()
23 $db = Database
::instance();
26 $res = $db->query('SELECT * FROM avail_config');
27 } catch(Kohana_Database_Exception
$e) {
28 // This most certainly (hrrm) was an installation
29 // instead of an upgrade, and as such, we already have
30 // the merlin.saved_reports table.
32 // Since it should be the usual case, we're keeping
36 foreach ($res->result(false) as $result) {
37 $objs = $db->query('SELECT `name` FROM avail_config_objects WHERE avail_config_objects.avail_id = '.$result['id']);
39 foreach ($objs as $obj)
40 $objects[] = $obj->name
;
41 $result['objects'] = $objects;
42 $opts = new Avail_options($result);
43 if (isset($result['alert_types'])) {
44 $op5opts = new Op5reports_options($result);
45 $op5opts->add_sub($opts);
48 if (!$opts->save($msg))
49 print 'avail '.$result['report_name'].': '.$msg."\n";
52 $res = $db->query('SELECT * FROM sla_config');
53 foreach ($res->result(false) as $result) {
54 $objs = $db->query('SELECT name FROM sla_config_objects WHERE sla_config_objects.sla_id = '.$result['id']);
56 foreach ($objs as $obj)
57 $objects[] = $obj->name
;
58 $result['objects'] = $objects;
59 $mnts = $db->query('SELECT value FROM sla_periods WHERE sla_periods.sla_id = '.$result['id']);
61 foreach ($mnts as $mnt)
62 $months[] = $mnt->value
;
63 $opts = new Sla_options($result);
64 if (isset($result['alert_types'])) {
65 $op5opts = new Op5reports_options($result);
66 $op5opts->add_sub($opts);
70 foreach ($res['months'] as $key => $_) {
71 $opts['months'][$key] = current($months);
74 if (!$opts->save($msg))
75 print 'sla '.$result['report_name'].': '.$msg."\n";
78 $res = $db->query('SELECT * FROM summary_config');
79 foreach ($res->result(false) as $result) {
80 $setting = @unserialize
($result['setting']);
83 $setting['report_name'] = $result['report_name'];
84 $opts = new Summary_options($setting);
85 if (!$opts->save($msg))
86 print 'summary '.$result['report_name'].': '.$msg."\n";