forked from Ecodev/newsletter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.ext_update.php
More file actions
100 lines (90 loc) · 3.76 KB
/
class.ext_update.php
File metadata and controls
100 lines (90 loc) · 3.76 KB
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
<?php
/* * *************************************************************
* Copyright notice
*
* (c) 2015
* 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!
* ************************************************************* */
/**
* Class to migrate DB records
*
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class ext_update
{
/**
* SQL queries to do migration
* @var array
*/
private $queries = array(
"UPDATE tx_scheduler_task SET serialized_task_object = REPLACE(serialized_task_object, 'O:29:\"Tx_Newsletter_Task_SendEmails\"', 'O:33:\"Ecodev\\\\Newsletter\\\\Task\\\\SendEmails\"');",
"UPDATE tx_scheduler_task SET serialized_task_object = REPLACE(serialized_task_object, 'O:31:\"Tx_Newsletter_Task_FetchBounces\"', 'O:35:\"Ecodev\\\\Newsletter\\\\Task\\\\FetchBounces\"');",
"UPDATE tx_newsletter_domain_model_recipientlist SET type = REPLACE(type, 'Tx_Newsletter_Domain_Model_RecipientList_', 'Ecodev\\\\Newsletter\\\\Domain\\\\Model\\\\RecipientList\\\\');",
"UPDATE tx_newsletter_domain_model_newsletter SET plain_converter = REPLACE(plain_converter, 'Tx_Newsletter_Domain_Model_PlainConverter_', 'Ecodev\\\\Newsletter\\\\Domain\\\\Model\\\\PlainConverter\\\\');",
);
/**
* Main function, returning the HTML content of the module
* @return string HTML to display
*/
public function main()
{
$content = '';
$content .= '<h2>Migration from Newsletter 2.2.3 to 2.3.0</h2>';
$content .= '<form name="migrateForm" action="" method ="post">';
$content .= '<p>Records in database from Newsletter 2.2.3, or earlier, will be migrated to 2.3.0, or later. This action is idempotent and can be repeated if necessary.</p>';
$content .= '<p><input type="submit" name="domigration" value ="Migrate" /></p>';
$content .= '</form>';
// Action! Makes the necessary update
$update = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('domigration');
// The update button was clicked, migrate stuff
if (!empty($update)) {
$recordCount = $this->doMigration();
$content .= '<h3>Results</h3>';
$content .= "<p>$recordCount records successfully migrated.</p>";
}
return $content;
}
/**
* Apply the migration
* @global \TYPO3\CMS\Core\Database\DatabaseConnection $TYPO3_DB
*/
private function doMigration()
{
global $TYPO3_DB;
$recordCount = 0;
foreach ($this->queries as $query) {
$res = $TYPO3_DB->sql_query($query);
$error = $TYPO3_DB->sql_error();
if ($error) {
die("<pre>" . $query . "<br>" . $error . "</pre>");
}
$recordCount += $TYPO3_DB->sql_affected_rows($res);
}
return $recordCount;
}
/**
* This method checks whether it is necessary to display the UPDATE option at all
*
* @param string $what What should be updated
*/
public function access($what = 'all')
{
return true;
}
}