Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Symphony 4.x #10

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions assets/multilingual_tag_field.publish.css

This file was deleted.

152 changes: 88 additions & 64 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@



define_safe(MTF_NAME, 'Field: Multilingual Tag List');
define_safe(MTF_GROUP, 'multilingual_tag_field');
define_safe('MTF_NAME', 'Field: Multilingual Tag List');
define_safe('MTF_GROUP', 'multilingual_tag_field');



Expand All @@ -22,48 +22,58 @@ class Extension_Multilingual_Tag_Field extends Extension
/*------------------------------------------------------------------------------------------------*/

public function install(){
return Symphony::Database()->query(sprintf(
"CREATE TABLE `%s` (
`id` int(11) unsigned NOT NULL auto_increment,
`field_id` int(11) unsigned NOT NULL,
`validator` varchar(50),
`pre_populate_source` varchar(15),
`def_ref_lang` enum('yes','no') NOT NULL default 'no',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
self::FIELD_TABLE
));
return Symphony::Database()
->create(self::FIELD_TABLE)
->ifNotExists()
->fields([
'id' => [
'type' => 'int(11)',
'auto' => true,
],
'field_id' => 'int(11)',
'validator' => 'varchar(50)',
'pre_populate_source' => 'varchar(15)',
'def_ref_lang' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
])
->keys([
'id' => 'primary',
'field_id' => 'key',
])
->execute()
->success();
}

public function update($previousVersion = false){
if( version_compare($previousVersion, '1.2', '<') ){
Symphony::Database()->query(sprintf(
"RENAME TABLE `tbl_fields_multilingualtag` TO `%s`;",
self::FIELD_TABLE
));

Symphony::Database()->query(sprintf(
"UPDATE tbl_fields SET type = 'multilingual_tag' WHERE type = '%s;",
'multilingualtag'
));
Symphony::Database()
->rename('tbl_fields_multilingualtag')
->to(self::FIELD_TABLE)
->execute()
->success();

Symphony::Database()
->update('tbl_fields')
->set([
'type' => 'multilingual_tag',
])
->where(['type' => 'multilingualtag'])
->execute()
->success();
}

return true;
}

public function uninstall(){
try{
Symphony::Database()->query(sprintf(
"DROP TABLE `%s`",
self::FIELD_TABLE
));
}
catch( DatabaseException $dbe ){
// table deosn't exist
}

return true;
return Symphony::Database()
->drop(self::FIELD_TABLE)
->ifExists()
->execute()
->success();
}


Expand Down Expand Up @@ -103,7 +113,7 @@ public function dAddCustomPreferenceFieldsets($context){
$group->appendChild(new XMLElement('legend', __(MTF_NAME)));

$label = Widget::Label(__('Consolidate entry data'));
$label->appendChild(Widget::Input('settings['.MTF_GROUP.'][consolidate]', 'yes', 'checkbox', array('checked' => 'checked')));
$label->prependChild(Widget::Input('settings['.MTF_GROUP.'][consolidate]', 'yes', 'checkbox', array('checked' => 'checked')));
$group->appendChild($label);
$group->appendChild(new XMLElement('p', __('Check this field if you want to consolidate database by <b>keeping</b> entry values of removed/old Language Driver language codes. Entry values of current language codes will not be affected.'), array('class' => 'help')));

Expand All @@ -116,10 +126,11 @@ public function dAddCustomPreferenceFieldsets($context){
* @param array $context
*/
public function dFLSavePreferences($context){
$fields = Symphony::Database()->fetch(sprintf(
'SELECT `field_id` FROM `%s`',
self::FIELD_TABLE
));
$fields = Symphony::Database()
->select(['field_id'])
->from(self::FIELD_TABLE)
->execute()
->rows();

if( is_array($fields) && !empty($fields) ){
$consolidate = $context['context']['settings'][MTF_GROUP]['consolidate'];
Expand All @@ -129,17 +140,21 @@ public function dFLSavePreferences($context){
$entries_table = 'tbl_entries_data_'.$field["field_id"];

try{
$show_columns = Symphony::Database()->fetch(sprintf(
"SHOW COLUMNS FROM `%s` LIKE 'handle-%%'",
$entries_table
));
$show_columns = Symphony::Database()
->showColumns()
->from($entries_table)
->like('handle-%%')
->execute()
->rows();
}
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"]
));
Symphony::Database()
->delete(self::FIELD_TABLE)
->where(['field_id' => $field['field_id']])
->execute()
->success();

continue;
}

Expand All @@ -153,26 +168,37 @@ public function dFLSavePreferences($context){

// If not consolidate option AND column lang_code not in supported languages codes -> Drop Column
if( ($consolidate !== 'yes') && !in_array($lc, $context['new_langs']) )
Symphony::Database()->query(sprintf(
'ALTER TABLE `%1$s`
DROP COLUMN `handle-%2$s`,
DROP COLUMN `value-%2$s`;',
$entries_table, $lc
));
Symphony::Database()
->alter($entries_table)
->drop([
'handle-' . $lc,
'value-' . $lc,
])
->execute()
->success();
else
$columns[] = $column['Field'];
}

// Add new fields
foreach( $context['new_langs'] as $lc )

if( !in_array('handle-'.$lc, $columns) )
Symphony::Database()->query(sprintf(
'ALTER TABLE `%1$s`
ADD COLUMN `handle-%2$s` varchar(255) default NULL,
ADD COLUMN `value-%2$s` varchar(50) default NULL;',
$entries_table, $lc
));
foreach( $context['new_langs'] as $lc ) {
if( !in_array('handle-'.$lc, $columns) ) {
Symphony::Database()
->alter($entries_table)
->add([
'handle-' . $lc => [
'type' => 'varchar(255)',
'null' => true,
],
'value-' . $lc => [
'type' => 'varchar(50)',
'null' => true,
],
])
->execute()
->success();
}
}
}
}
}
Expand All @@ -192,8 +218,6 @@ public static function appendAssets(){
self::$assets_loaded = true;

$page = Administration::instance()->Page;

$page->addStylesheetToHead(URL.'/extensions/'.MTF_GROUP.'/assets/'.MTF_GROUP.'.publish.css', 'screen', null, false);
}
}

Expand Down
6 changes: 5 additions & 1 deletion extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
</author>
</authors>
<dependencies>
<dependency version="1.5">https://github.com/vlad-ghita/frontend_localisation</dependency>
<dependency version="1.5">frontend_localisation</dependency>
</dependencies>
<releases>
<release version="2.0.0" date="TBA" min="4.0.0" max="4.x.x" php-min="5.6.x" php-max="7.x.x"><![CDATA[
* Update for Symphony 4.x
* Code refactoring for Database and EQFA
]]></release>
<release version="1.2.3" date="2017-05-23" min="2.3" max="2.x.x"><![CDATA[
* Fixed broken updater in 1.2.2
]]></release>
Expand Down
Loading