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

PHP7 Compatibility release #84

Open
wants to merge 19 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
137 changes: 95 additions & 42 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,61 @@
Class extension_selectbox_link_field extends Extension{

public function install(){
try{
Symphony::Database()->query("
CREATE TABLE IF NOT EXISTS `tbl_fields_selectbox_link` (
`id` int(11) unsigned NOT NULL auto_increment,
`field_id` int(11) unsigned NOT NULL,
`allow_multiple_selection` enum('yes','no') NOT NULL default 'no',
`hide_when_prepopulated` enum('yes','no') NOT NULL default 'no',
`related_field_id` VARCHAR(255) NOT NULL,
`limit` int(4) unsigned NOT NULL default '20',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
");
}
catch(Exception $e){
return false;
}

return true;
return Symphony::Database()
->create('tbl_fields_selectbox_link')
->ifNotExists()
->fields([
'id' => [
'type' => 'int(11)',
'auto' => true,
],
'field_id' => 'int(11)',
'allow_multiple_selection' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
'hide_when_prepopulated' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
'related_field_id' => 'varchar(255)',
'limit' => [
'type' => 'int(4)',
'default' => 20
],
])
->keys([
'id' => 'primary',
'field_id' => 'key',
])
->execute()
->success();
}

public function uninstall(){
if(parent::uninstall() == true){
Symphony::Database()->query("DROP TABLE `tbl_fields_selectbox_link`");
return true;
}

return false;
return Symphony::Database()
->drop('tbl_fields_selectbox_link')
->ifExists()
->execute()
->success();
}

public function update($previousVersion = false){
try{
if(version_compare($previousVersion, '1.27', '<')){
Symphony::Database()->query(
"ALTER TABLE `tbl_fields_selectbox_link` ADD `hide_when_prepopulated` ENUM('yes','no') DEFAULT 'no'"
);
Symphony::Database()
->alter('tbl_fields_selectbox_link')
->add([
'hide_when_prepopulated' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
])
->execute()
->success();
}
}
catch(Exception $e){
Expand All @@ -47,9 +66,16 @@ public function update($previousVersion = false){

try{
if(version_compare($previousVersion, '1.6', '<')){
Symphony::Database()->query(
"ALTER TABLE `tbl_fields_selectbox_link` ADD `limit` INT(4) UNSIGNED NOT NULL DEFAULT '20'"
);
Symphony::Database()
->alter('tbl_fields_selectbox_link')
->add([
'limit' => [
'type' => 'int(4)',
'default' => 20
],
])
->execute()
->success();
}
}
catch(Exception $e){
Expand All @@ -58,9 +84,11 @@ public function update($previousVersion = false){

if(version_compare($previousVersion, '1.15', '<')){
try{
$fields = Symphony::Database()->fetchCol('field_id',
"SELECT `field_id` FROM `tbl_fields_selectbox_link`"
);
$fields = Symphony::Database()
->select(['field_id'])
->from('tbl_fields_selectbox_link')
->execute()
->column('field_id');
}
catch(Exception $e){
// Discard
Expand All @@ -69,28 +97,49 @@ public function update($previousVersion = false){
if(is_array($fields) && !empty($fields)){
foreach($fields as $field_id){
try{
Symphony::Database()->query(
"ALTER TABLE `tbl_entries_data_{$field_id}`
CHANGE `relation_id` `relation_id` INT(11) UNSIGNED NULL DEFAULT NULL"
);
Symphony::Database()
->alter('tbl_entries_data_' . $field_id)
->modify([
'relation_id' => [
'type' => 'int(11)',
'null' => true,
],
])
->execute()
->success();
}
catch(Exception $e){
// Discard
}
}
}
}

try{
Symphony::Database()->query("ALTER TABLE `tbl_fields_selectbox_link` CHANGE `related_field_id` `related_field_id` VARCHAR(255) NOT NULL");
Symphony::Database()
->alter('tbl_fields_selectbox_link')
->modify([
'related_field_id' => 'varchar(255)'
])
->execute()
->success();
}
catch(Exception $e){
// Discard
}

if(version_compare($previousVersion, '1.19', '<')){
try{
Symphony::Database()->query("ALTER TABLE `tbl_fields_selectbox_link` ADD COLUMN `show_association` enum('yes','no') NOT NULL default 'yes'");
Symphony::Database()
->alter()
->add([
'show_association' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'yes',
],
])
->execute()
->success();
}
catch(Exception $e){
// Discard
Expand All @@ -99,7 +148,11 @@ public function update($previousVersion = false){

if(version_compare($previousVersion, '1.31', '<')){
try{
Symphony::Database()->query("ALTER TABLE `tbl_fields_selectbox_link` DROP COLUMN `show_association`");
Symphony::Database()
->alter('tbl_fields_selectbox_link')
->drop('show_association')
->execute()
->success();
}
catch(Exception $e){
// Discard
Expand Down
8 changes: 7 additions & 1 deletion extension.meta.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension id="selectbox_link_field" status="released" xmlns="http://getsymphony.com/schemas/extension/1.0">
<name>Select Box Link Field</name>
<name>Field: Select Box Link</name>
<description>Linking two sections together</description>
<repo type="github">https://github.com/symphonycms/selectbox_link_field</repo>
<url type="discuss">https://getsymphony.com/discuss/thread/473/</url>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please make it https://www...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be more specific ? @nitriques

Expand All @@ -15,6 +15,12 @@
</author>
</authors>
<releases>
<release version="3.0.0" date="TBA" min="3.0.0" max="4.x.x" php-min="5.6.x" php-max="7.x.x">
- Update for Symphony 3.x
- PHP7 Compatibility
- Code refactoring for Database and EQFA
- Replace deprecated method fetch() by select()
</release>
<release version="2.0.2" date="2017-10-06" min="2.6.0" max="2.x.x">
- [#87](https://github.com/symphonycms/selectbox_link_field/issues/87) Add missing canPrePopulate() function
</release>
Expand Down
Loading