This repository has been archived by the owner on May 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
class.ext_update.php
91 lines (77 loc) · 3.18 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
<?php
/**
* Copyright (c) 2012, ROQUIN B.V. (C), http://www.roquin.nl
*
* @author: Jochem de Groot <[email protected]>
* @file: class.ext_update.php
* @created: 26-9-12 16:28
* @description: Update class for updating news event from version 2.0.X to newer versions
*/
class ext_update extends t3lib_SCbase {
/**
* Main method that is called whenever UPDATE! menu was clicked. This method outputs the result of the update in HTML
*
* @return string: HTML to display
*/
public function main() {
$affectedRows = 0;
$errorMessage = '';
$this->content = '';
$this->doc = t3lib_div::makeInstance('noDoc');
$this->doc->backPath = $GLOBALS['BACK_PATH'];
if($this->updateNewsEventRecords($errorMessage, $affectedRows) == 0) {
$this->content .= $this->doc->section('', 'The update has been performed successfully: ' . $affectedRows . ' row(s) affected.');
} else {
$this->content .= $this->doc->section('', 'An error occurred while preforming updates. Error: ' . $errorMessage);
}
return $this->content;
}
/**
* Updates news type and news event tx_roqnewsevent_is_event attribute in database news event records
*
* @param $errorMessage: stores the error message, if an error has been occurred
* @param $affectedRows: stores the affected rows, when the query has been executed
* @return integer: returns error code (0 == success)
*/
protected function updateNewsEventRecords(&$errorMessage, &$affectedRows) {
$errorCode = 0;
$affectedRows = 0;
$result = FALSE;
$result = $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
'tx_news_domain_model_news',
"tx_news_domain_model_news.type LIKE 'Tx_RoqNewsevent_Event'",
array(
'type' => 0,
'tx_roqnewsevent_is_event' => 1,
)
);
if($result) {
$affectedRows = $GLOBALS['TYPO3_DB']->sql_affected_rows();
} else {
$errorCode = $GLOBALS['TYPO3_DB']->sql_errno();
$errorMessage = 'Could not update table tx_news_domain_model_news. ' . $GLOBALS['TYPO3_DB']->sql_error() .' (Error code: ' . $errorCode . ').';
}
return $errorCode;
}
/**
* Check if the update is necessary, and whether the "UPDATE!" menu item should be shown.
*
* @return boolean: returns true if update should be performed
*/
public function access() {
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_news_domain_model_news.type',
'tx_news_domain_model_news',
"tx_news_domain_model_news.type LIKE 'Tx_RoqNewsevent_Event'"
);
// check if there are news records which must be updated
if (($result !== FALSE) && ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0)) {
return TRUE;
}
return FALSE;
}
}
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']);
}
?>