-
Notifications
You must be signed in to change notification settings - Fork 24
/
remove_headlinecontroller.php
135 lines (121 loc) · 4.16 KB
/
remove_headlinecontroller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* This file is part of Exponent
* Exponent is free software; you can redistribute
* it and/or modify it under the terms of the GNU
* General Public License as published by the Free
* Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The file that holds the remove_headlinecontroller class
*
* @link http://www.gnu.org/licenses/gpl.txt GPL http://www.gnu.org/licenses/gpl.txt
* @package Exponent-CMS
* @copyright 2004-2011 OIC Group, Inc.
* @author Adam Kessler <adam@oicgroup.net>
* @version 2.0.0
*/
/**
* This is the class remove_headlinecontroller
*
* @subpackage Upgrade
* @package Installation
*/
class remove_headlinecontroller extends upgradescript {
protected $from_version = '1.99.0';
protected $to_version = '2.0.1';
/**
* name/title of upgrade script
* @return string
*/
function name() { return "Remove the (deprecated) Headline Controller"; }
/**
* generic description of upgrade script
* @return string
*/
function description() { return "Beginning with Exponent 2.0.0 Beta4, the Headline Controller is replaced by the Text Controller. This Script converts headline modules to text modules and then deletes the headlines"; }
/**
* additional test(s) to see if upgrade script should be run
* @return bool
*/
function needed() {
return false; // TODO this line is set to false to disable this sample script
}
/**
* coverts all headline modules/items into text modules/items and deletes headline controller files
* @return bool
*/
function upgrade() {
global $db;
// convert each headline module reference to a text module reference
$srs = $db->selectObjects('sectionref',"module = 'headlineController'");
foreach ($srs as $sr) {
$sr->module = 'textController';
$db->updateObject($sr,'sectionref');
}
$lrs = $db->selectObjects('locationref',"module = 'headlineController'");
foreach ($lrs as $lr) {
$lr->module = 'textController';
$db->updateObject($lr,'locationref');
}
$gps = $db->selectObjects('grouppermission',"module = 'headlineController'");
foreach ($gps as $gp) {
$gp->module = 'textController';
$db->updateObject($gp,'grouppermission');
}
$ups = $db->selectObjects('userpermission',"module = 'headlineController'");
foreach ($ups as $up) {
$up->module = 'textController';
$db->updateObject($up,'userpermission');
}
// convert each headline module to a text module
$modules_converted = 0;
$cns = $db->selectObjects('container',"internal LIKE '%headlineController%'");
foreach ($cns as $cn) {
$cloc = expUnserialize($cn->internal);
$cloc->mod = 'textController';
$cn->internal = serialize($cloc);
$cn->view = 'showall';
$cn->action = 'showall';
$db->updateObject($cn,'container');
$modules_converted += 1;
}
// create a text item for each headline item
$headlines_converted = 0;
$headlines = $db->selectObjects('headline',"1");
foreach ($headlines as $hl) {
$text = new text();
$loc = expUnserialize($hl->location_data);
$loc->mod = "text";
$text->location_data = serialize($loc);
$text->title = $hl->title;
$text->poster = $hl->poster;
$text->save();
$text->created_at = $hl->created_at;
$text->edited_at = $hl->edited_at;
$text->update();
$headlines_converted += 1;
}
// delete headline table
$db->dropTable('headline');
// check if the headline controller files are there and remove them
$files = array(
BASE."framework/core/database/definitions/headline.php",
BASE."framework/datatypes/headline.php",
BASE."framework/modules/headline/"
);
// delete the files.
$removed = 0;
$errors = 0;
foreach ($files as $file) {
if (is_really_writable($file)) {
unlink ($file);
$removed += 1;
} else {
$errors += 1;
}
}
return $modules_converted." Headline modules were converted.<br>".$headlines_converted." Headlines were converted.<br>".$removed." files were deleted.<br>".$errors." files could not be removed.";
}
}
?>