-
Notifications
You must be signed in to change notification settings - Fork 0
/
updates.php
executable file
·154 lines (121 loc) · 3.22 KB
/
updates.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/*
* This file is part of the Icybee package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Icybee\Modules\Editor;
use ICanBoogie\Updater\Update;
use ICanBoogie\Updater\AssertionFailed;
use ICanBoogie\Modules\Thumbnailer\Version;
/**
* @module editor
*/
class Update20120101 extends Update
{
/**
* Replace editor `moo` with editor `rte` in contents.
*/
public function update_editor_moo_in_contents()
{
$model = $this->app->models['contents'];
$count = $model->filter_by_editor('moo')->count;
if (!$count)
{
throw new AssertionFailed(__FUNCTION__, [ 'moo' ]);
}
$model('UPDATE {self} SET editor = "rte" WHERE editor = "moo"');
}
/**
* Replace editor `moo` with editor `rte` in page contents.
*/
public function update_editor_moo_in_page_contents()
{
$model = $this->app->models['pages/contents'];
$count = $model->filter_by_editor('moo')->count;
if (!$count)
{
throw new AssertionFailed(__FUNCTION__, [ 'moo' ]);
}
$model('UPDATE {self} SET editor = "rte" WHERE editor = "moo"');
}
/**
* Replace editor `adjustnode` with editor `node` in contents.
*/
public function update_editor_adjustnode_in_contents()
{
$model = $this->app->models['contents'];
$count = $model->filter_by_editor('adjustnode')->count;
if (!$count)
{
throw new AssertionFailed(__FUNCTION__, [ 'adjustnode' ]);
}
$model('UPDATE {self} SET editor = "node" WHERE editor = "adjustnode"');
}
/**
* Replace editor `adjustnode` with editor `node` in page contents.
*/
public function update_editor_adjustnode_in_page_contents()
{
$model = $this->app->models['pages/contents'];
$count = $model->filter_by_editor('adjustnode')->count;
if (!$count)
{
throw new AssertionFailed(__FUNCTION__, [ 'adjustnode' ]);
}
$model('UPDATE {self} SET editor = "node" WHERE editor = "adjustnode"');
}
public function update_editor_adjustnode_data()
{
}
}
/**
* @module editor
*/
class Update20140619 extends Update
{
public function update_rte_thumbnails_in_pages()
{
$model = $this->app->models['pages/contents'];
/* @var $contents \Icybee\Modules\Pages\Content[] */
$contents = $model
->filter_by_editor('rte')
->where('content LIKE "%/api/images/%/thumbnail?%"')
->all;
if (!$contents)
{
throw new AssertionFailed(__FUNCTION__, [ "/api/images/%/thumbnail?" ]);
}
foreach ($contents as $content)
{
$html = $content->content;
$html = preg_replace_callback('#(/api/images/(\d+)/thumbnail\?[^"\s]+)#', function($matches) {
list( ,$url, $nid) = $matches;
$encoded = strpos($url, '&');
if ($encoded)
{
$url = html_entity_decode($url);
}
$components = parse_url($url);
$path = $components['path'];
$query = $components['query'];
parse_str($query, $query);
if (isset($query['quality']) && $query['quality'] == 80)
{
unset($query['quality']);
}
if (isset($query['q']) && $query['q'] == 80)
{
unset($query['q']);
}
$url = "/api/images/$nid/" . new Version($query);
return $url;
}, $html);
$content->content = $html;
$content->save();
}
}
}