forked from TYPO3-svn-archive/file_list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.ext_update.php
200 lines (181 loc) · 6.26 KB
/
class.ext_update.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/***************************************************************
* Copyright notice
*
* (c) 2009-2012 Xavier Perseguers <[email protected]>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project 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 GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
require_once(PATH_t3lib . 'class.t3lib_scbase.php');
/**
* Update class for the 'file_list' extension.
*
* @package TYPO3
* @subpackage tx_filelist
* @author Xavier Perseguers <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html
* @version SVN: $Id$
*/
class ext_update extends t3lib_SCbase {
/**
* Checks whether the "UPDATE!" menu item should be shown. If no old configuration (in
* dedicated fields of tt_content) is found, should return FALSE; otherwise TRUE.
*
* @return boolean
*/
public function access() {
return count($this->getPluginsWithOldConfiguration()) > 0;
}
/**
* Main method that is called whenever UPDATE! menu was clicked. This method outputs a
* HTML form to update the configuration of all plugins of the website.
*
* @return string HTML to display
*/
public function main() {
$this->content = '';
$this->doc = t3lib_div::makeInstance('noDoc');
$this->doc->backPath = $GLOBALS['BACK_PATH'];
$this->doc->form = '<form action="" method="post">';
$title = 'File List Plugin Configuration';
$this->content .= $this->doc->startPage($title);
$this->content .= $this->doc->header($title);
$this->content .= $this->doc->spacer(5);
$this->content .= $this->doc->section('',
'This extension does not need any dedicated columns in table tt_content anymore. ' .
'These columns were used to store the plugin configuration. This update wizard ' .
'detected that you still have plugins whose configuration has not yet been upgrade. ' .
'This form allows you to upgrade your existing file_list plugins to use the new ' .
'FlexForm configuration.'
);
if (t3lib_div::_GET('upgrade')) {
$this->content .= $this->upgrade();
} else {
$this->content .= $this->prepareUpgrade();
}
return $this->content;
}
/**
* Prepares the upgrade process.
*
* @return string
*/
protected function prepareUpgrade() {
$oldPlugins = $this->getPluginsWithOldConfiguration();
return $this->doc->section('Configuration Upgrade',
count($oldPlugins) . ' plugins with old configuration were found. ' .
'<a href="' . t3lib_div::linkThisScript(array('upgrade' => 1)) . '">Click here</a> ' .
'to start the upgrade process.'
);
}
/**
* Performs the configuration upgrade.
*
* @return string
*/
protected function upgrade() {
$oldPlugins = $this->getPluginsWithOldConfiguration();
foreach ($oldPlugins as $plugin) {
$GLOBALS['TYPO3_DB']->exec_UPDATEquery(
'tt_content',
'uid=' . $plugin['uid'],
array(
'tstamp' => time(),
'pi_flexform' => $this->getFlexFormConfiguration($plugin),
'tx_filelist_path' => '',
)
);
}
return $this->doc->section('Configuration Upgrade',
count($oldPlugins) . ' plugins were upgraded. You should now consider ' .
'opening the Install Tool and removing deprecated file_list columns from ' .
'table tt_content by running the Compare tool.'
);
}
/**
*
* @param array $config
* @return string
*/
protected function getFlexFormConfiguration(array $config) {
$flexform = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3FlexForms>
<data>
<sheet index="sDEF">
<language index="lDEF">
<field index="path">
<value index="vDEF">%s</value>
</field>
<field index="order_by">
<value index="vDEF">%s</value>
</field>
<field index="sort_direction">
<value index="vDEF">%s</value>
</field>
<field index="new_duration">
<value index="vDEF">%s</value>
</field>
<field index="fe_sort">
<value index="vDEF">%s</value>
</field>
</language>
</sheet>
</data>
</T3FlexForms>';
$path = $config['tx_filelist_path'];
switch ($config['tx_filelist_order_by']) {
case '1':
$order_by = 'date';
break;
case '2':
$order_by = 'size';
break;
default:
$order_by = 'name';
}
$direction = $config['tx_filelist_order_sort'] == '1' ? 'desc' : 'asc';
$duration = intval($config['tx_filelist_show_new']);
$fe_sort = intval($config['tx_filelist_fe_user_sort']);
return sprintf($flexform, $path, $order_by, $direction, $duration, $fe_sort);
}
/**
* Returns a list of plugins that have not yet been upgraded to use the FlexForm configuration.
*
* @return array Array of "light" tt_content rows
*/
protected function getPluginsWithOldConfiguration() {
// Do not take deleted flag into account as we wish to upgrade ALL plugins
$records = t3lib_BEfunc::getRecordsByField('tt_content', 'list_type', 'file_list_pi1');
$fields = t3lib_div::trimExplode(',', 'uid,pid,tx_filelist_path,tx_filelist_order_by,tx_filelist_order_sort,tx_filelist_show_new,tx_filelist_fe_user_sort');
$plugins = array();
foreach ($records as $record) {
if (isset($record['tx_filelist_path']) && $record['tx_filelist_path'] !== '') {
$plugin = array();
foreach ($fields as $field) {
$plugin[$field] = $record[$field];
}
$plugins[] = $plugin;
}
}
return $plugins;
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/file_list/class.ext_update.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/file_list/class.ext_update.php']);
}
?>