forked from kartolo/direct_mail
-
Notifications
You must be signed in to change notification settings - Fork 1
/
class.ext_update.php
134 lines (122 loc) · 4.3 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
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Ivan Kartolo <ivan at kartolo dot de)
* 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
/**
* Class for updating Direct Mail to version 3
*
* @author Ivan Kartolo <ivan at kartolo dot de>
* @package TYPO3
* @subpackage tx_directmail
*/
class ext_update
{
/**
* Main function, returning the HTML content of the module
*
* @return string HTML
*/
public function main()
{
$GLOBALS['LANG']->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf');
$content = $this->displayWarning();
if (!GeneralUtility::_GP('do_update')) {
$onClick = "document.location='" . GeneralUtility::linkThisScript(array('do_update' => 1)) . "'; return false;";
$content .= htmlspecialchars($GLOBALS['LANG']->getLL('update_convert_now')) . '
<br /><br />
<form action=""><input type="submit" value="' . htmlspecialchars($GLOBALS['LANG']->getLL('update_convert_do_it_now')) . '" onclick="' . htmlspecialchars($onClick) . '"></form>
';
} else {
$updated = $this->convertTable();
$content .= sprintf($GLOBALS['LANG']->getLL('update_convert_result'), $updated);
}
return $content;
}
/**
* Convert the mailcontent data to base64 coded
* @return int $i: the counter
*/
public function convertTable()
{
$dmailRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'uid',
'sys_dmail',
'1=1'
);
$i = 0;
foreach ($dmailRows as $row) {
// get the mailContent
$mailContent = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'mailContent',
'sys_dmail',
'uid = ' . $row['uid']
);
if (is_array(unserialize($mailContent[0]['mailContent']))) {
// update the table
$GLOBALS['TYPO3_DB']->exec_UPDATEquery(
'sys_dmail',
'uid = ' . $row['uid'],
array('mailContent' => base64_encode($mailContent[0]['mailContent']))
);
// add the counter
$i++;
}
}
return $i;
}
/**
* Checks how many rows are found and returns true if there are any
*
* @return bool true if user have access, otherwise false
*/
public function access()
{
// We cannot update before the extension is installed: required tables are not yet in TCA
if (ExtensionManagementUtility::isLoaded('direct_mail')) {
return true;
} else {
return false;
}
}
/**
* Enter description here ...
* @return string
*/
public function displayWarning()
{
$out = '
<div style="padding:15px 15px 20px 0;">
<div class="typo3-message message-warning">
<div class="message-header">' . $GLOBALS['LANG']->sL('LLL:EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf:update_warningHeader') . '</div>
<div class="message-body">
' . $GLOBALS['LANG']->sL('LLL:EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf:update_warningMsg') . '
</div>
</div>
</div>';
return $out;
}
}