Merge of branch 2.0.1.1-externalurls with trunk
[TYPO3CMS/Extensions/roq_newsevent.git] / class.ext_update.php
1 <?php
2 /**
3 * Copyright (c) 2012, ROQUIN B.V. (C), http://www.roquin.nl
4 *
5 * @author: Jochem de Groot <jochem@roquin.nl>
6 * @file: class.ext_update.php
7 * @created: 26-9-12 16:28
8 * @description: Update class for updating news event from version 2.0.X to newer versions
9 */
10
11 class ext_update extends t3lib_SCbase {
12
13 /**
14 * Main method that is called whenever UPDATE! menu was clicked. This method outputs the result of the update in HTML
15 *
16 * @return string: HTML to display
17 */
18 function main() {
19 $affectedRows = 0;
20 $errorMessage = '';
21 $this->content = '';
22 $this->doc = t3lib_div::makeInstance('noDoc');
23
24 $this->doc->backPath = $GLOBALS['BACK_PATH'];
25
26 if($this->updateNewsEventRecords($errorMessage, $affectedRows) == 0) {
27 $this->content .= $this->doc->section('','The update has been performed successfully: ' . $affectedRows . " row(s) affected.");
28 } else {
29 $this->content .= $this->doc->section('','An error occurred while preforming updates. Error: ' . $errorMessage);
30 }
31
32 return $this->content;
33 }
34
35 /**
36 * Updates news type and news event tx_roqnewsevent_is_event attribute in database news event records
37 *
38 * @param $errorMessage: stores the error message, if an error has been occurred
39 * @param $affectedRows: stores the affected rows, when the query has been executed
40 * @return integer: returns error code (0 == success)
41 */
42 protected function updateNewsEventRecords(&$errorMessage, &$affectedRows) {
43 $errorCode = 0;
44 $affectedRows = 0;
45 $result = false;
46
47 $result = $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
48 "tx_news_domain_model_news",
49 "type='Tx_RoqNewsevent_Event'",
50 array(
51 'type' => 0,
52 'tx_roqnewsevent_is_event' => 1,
53 )
54 );
55
56 if($result) {
57 $affectedRows = $GLOBALS['TYPO3_DB']->sql_affected_rows();
58 } else {
59 $errorCode = $GLOBALS['TYPO3_DB']->sql_errno();
60 $errorMessage = 'Could not update table tx_news_domain_model_news. ' . $GLOBALS['TYPO3_DB']->sql_error() .' (Error code: ' . $errorCode . ').';
61 }
62
63 return $errorCode;
64 }
65
66 /**
67 * Check if the update is necessary, and whether the "UPDATE!" menu item should be shown.
68 *
69 * @return boolean: returns true if update should be performed
70 */
71 function access() {
72 $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery("type","tx_news_domain_model_news","type='Tx_RoqNewsevent_Event'");
73
74 // check if news type must be updated
75 if (($result) && ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0)) {
76 return true;
77 }
78
79 return false;
80 }
81 }
82
83 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/file_list/class.ext_update.php']) {
84 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/file_list/class.ext_update.php']);
85 }
86
87 ?>