-
Notifications
You must be signed in to change notification settings - Fork 1
/
extension.driver.php
142 lines (113 loc) · 4.01 KB
/
extension.driver.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
135
136
137
138
139
140
141
142
<?php
require_once EXTENSIONS.'/reflectionfield/extension.driver.php';
class Extension_Multilingual_Reflection extends Extension_ReflectionField
{
const FIELD_TABLE = 'tbl_fields_multilingual_reflection';
/*------------------------------------------------------------------------------------------------*/
/* Installation */
/*------------------------------------------------------------------------------------------------*/
public function uninstall(){
Symphony::Database()->query( sprintf( "DROP TABLE `%s`", self::FIELD_TABLE ) );
}
public function install(){
Symphony::Database()->query( sprintf(
"CREATE TABLE IF NOT EXISTS `%s` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`field_id` INT(11) UNSIGNED NOT NULL,
`xsltfile` VARCHAR(255) DEFAULT NULL,
`expression` VARCHAR(255) DEFAULT NULL,
`formatter` VARCHAR(255) DEFAULT NULL,
`override` ENUM('yes', 'no') DEFAULT 'no',
`hide` ENUM('yes', 'no') DEFAULT 'no',
`fetch_associated_counts` ENUM('yes','no') DEFAULT 'no',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
self::FIELD_TABLE
) );
return true;
}
/*------------------------------------------------------------------------------------------------*/
/* Delegates */
/*------------------------------------------------------------------------------------------------*/
public function getSubscribedDelegates(){
return array(
array(
'page' => '/publish/new/',
'delegate' => 'EntryPostCreate',
'callback' => 'compileBackendFields'
),
array(
'page' => '/publish/edit/',
'delegate' => 'EntryPostEdit',
'callback' => 'compileFields'
),
array(
'page' => '/frontend/',
'delegate' => 'EventPostSaveFilter',
'callback' => 'compileFields'
),
array(
'page' => '/extensions/frontend_localisation/',
'delegate' => 'FLSavePreferences',
'callback' => 'dFLSavePreferences'
),
);
}
public function compileFields($context){
foreach(self::$fields as $field){
$field->compile( $context['entry'] );
}
}
public function dFLSavePreferences($context){
$fields = Symphony::Database()->fetch( sprintf( 'SELECT `field_id` FROM `%s`', self::FIELD_TABLE ) );
if( $fields ){
// Foreach field check multi language values foreach language
foreach($fields as $field){
$entries_table = 'tbl_entries_data_'.$field["field_id"];
try{
$show_columns = Symphony::Database()->fetch( "SHOW COLUMNS FROM `{$entries_table}` LIKE 'handle-%';" );
} catch( DatabaseException $dbe ){
// Field doesn't exist. Better remove it's settings
Symphony::Database()->query( sprintf(
"DELETE FROM `%s` WHERE `field_id` = %s;",
self::FIELD_TABLE, $field["field_id"] )
);
continue;
}
$columns = array();
// Remove obsolete fields
if( $show_columns ){
foreach($show_columns as $column){
$lc = substr( $column['Field'], strlen( $column['Field'] ) - 2 );
// If not consolidate option AND column lang_code not in supported languages codes -> Drop Column
if( !in_array( $lc, $context['new_langs'] ) ){
Symphony::Database()->query( sprintf( "
ALTER TABLE `%s`
DROP COLUMN `handle-{$lc}`,
DROP COLUMN `value-{$lc}`,
DROP COLUMN `value_formatted-{$lc}`;",
$entries_table ) );
}
else{
$columns[] = $column['Field'];
}
}
}
// Add new fields
foreach($context['new_langs'] as $lc){
// If column lang_code doesn't exist in the language drop columns
if( !in_array( 'handle-'.$lc, $columns ) ){
Symphony::Database()->query( sprintf( "
ALTER TABLE `%s`
ADD COLUMN `handle-{$lc}` varchar(255) default NULL,
ADD COLUMN `value-{$lc}` int(11) unsigned NULL,
ADD COLUMN `value_formatted-{$lc}` varchar(255) default NULL;",
$entries_table ) );
}
}
}
}
}
}
?>