|
1
|
|
|
<?php |
|
2
|
|
|
namespace Fab\Vidi; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* This file is part of the TYPO3 CMS project. |
|
6
|
|
|
* |
|
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
9
|
|
|
* of the License, or any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please read the |
|
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
13
|
|
|
* |
|
14
|
|
|
* The TYPO3 project - inspiring people to share! |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Updater script for Ichtus. |
|
19
|
|
|
*/ |
|
20
|
|
|
class ext_update { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @return bool |
|
24
|
|
|
*/ |
|
25
|
|
|
public function access() { |
|
26
|
|
|
return TRUE; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @return string |
|
31
|
|
|
*/ |
|
32
|
|
|
public function main() { |
|
33
|
|
|
$output[] = $this->updateSelections(); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
return sprintf('<ul><li style="float: none">%s</li></ul>', implode('</li><li style="float: none">', $output)); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function updateSelections() { |
|
42
|
|
|
|
|
43
|
|
|
$tableName = 'tx_vidi_selection'; |
|
44
|
|
|
$fields = $this->getDatabaseConnection()->admin_get_fields($tableName); |
|
45
|
|
|
|
|
46
|
|
|
if (!isset($fields['speaking_query'])) { |
|
47
|
|
|
$sql = 'ALTER TABLE tx_vidi_selection ADD speaking_query text;'; |
|
48
|
|
|
$this->getDatabaseConnection()->sql_query($sql); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$sql = 'UPDATE tx_vidi_selection SET speaking_query = query WHERE (speaking_query = "" OR speaking_query is NULL) AND query != "";'; |
|
52
|
|
|
$this->getDatabaseConnection()->sql_query($sql); |
|
53
|
|
|
|
|
54
|
|
|
$output = '<br/><strong>Table tx_vidi_selection has been updated</strong><br/>'; |
|
55
|
|
|
return $output; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Return a pointer to the database. |
|
60
|
|
|
* |
|
61
|
|
|
* @return \TYPO3\CMS\Core\Database\DatabaseConnection |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function getDatabaseConnection() { |
|
|
|
|
|
|
64
|
|
|
return $GLOBALS['TYPO3_DB']; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.