Merge branch 'maint/7.0'
[ninja.git] / application / controllers / db_migrations.php
blobf48fab34d46a5d4560e0d68cf75358434735ca5e
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.";
10 die(1);
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());
18 /**
19 * reports from per-report-type tables to all-in-one
21 public function v13_to_v14()
23 $db = Database::instance();
25 try {
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
33 // quiet. Shhh.
34 return;
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']);
38 $objects = array();
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);
46 $opts = $op5opts;
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']);
55 $objects = array();
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']);
60 $months = array();
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);
67 $opts = $op5opts;
69 reset($months);
70 foreach ($res['months'] as $key => $_) {
71 $opts['months'][$key] = current($months);
72 next($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']);
81 if (!$setting)
82 continue;
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";