-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass.ext_update.php
More file actions
107 lines (94 loc) · 2.78 KB
/
Copy pathclass.ext_update.php
File metadata and controls
107 lines (94 loc) · 2.78 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
101
102
103
104
105
106
107
<?php
namespace Laxap\Videoce;
/*
*
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
*
*/
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
/**
* This class updates videoce from version 0.8.x to 0.9.x
* @package Videoce
* @author Pascal Mayer <typo3@lascap.ch>
*
*/
class ext_update {
/** @var \TYPO3\CMS\Core\Database\DatabaseConnection */
protected $dbCon;
/**
* @var string
*/
protected $dbName = '';
/**
* @var string
*/
protected $tblContent = 'tt_content';
/**
* Constructor, assigns dbCon.
*/
public function __construct() {
$this->dbCon = $GLOBALS['TYPO3_DB'];
}
/**
* Checks if the script should execute.
* @return bool
*/
public function access() {
if ( ! isset($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname']) ) {
return false;
}
return true;
}
/**
* Runs the update process.
*/
public function main() {
$this->dbName = $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname'];
$fieldsExist = 0;
if ( $this->checkIfFieldExist('image_link') ) {
$fieldsExist++;
$this->copyField('image_link', 'bodytext');
}
if ( $this->checkIfFieldExist('imagecaption') ) {
$fieldsExist++;
$this->copyField('imagecaption', 'tx_videoce_caption');
}
if ( $fieldsExist == 0 ) {
return 'The fields image_link and imagecaption do not exist in tt_content. Nothing to copy.';
}
return 'Video elements updated!';
}
/**
* @param string $field
* @return bool
*/
protected function checkIfFieldExist($field) {
$ret = $this->dbCon->sql_query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . $this->dbName . "' AND TABLE_NAME = '" . $this->tblContent . "' AND COLUMN_NAME = '" . $field . "'");
if ( ! $ret ) {
return false;
}
if ( ! $this->dbCon->sql_fetch_assoc($ret) ) {
return false;
}
return true;
}
/**
* @param string $oldField
* @param string $newField
* @return bool
*/
protected function copyField($oldField, $newField) {
$ret = $this->dbCon->sql_query("UPDATE " . $this->tblContent . " SET " . $newField . "=" . $oldField . " WHERE CType='videoce_videocontent'");
return true;
}
}
?>