If this is your first visit, check our documentation. To post, register or login.
Forums / Community Contributed Add-Ons / Contribution-Writing Guidelines / Mod Authors: Please read if you are creating install.sql files

Mod Authors: Please read if you are creating install.sql files

Started by swguy on 14 Apr 2012, 9:00 AM · Views: 15,873

Results 1 to 3 of 3
14 Apr 2012, 9:00 AM
#1
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,760
Plugin Contributions:
56

Mod Authors: Please read if you are creating install.sql files

Applies to all versions.

Please do not do this:

SET @configuration_group_id=0;
SELECT @configuration_group_id:=configuration_group_id
FROM configuration_group
WHERE configuration_group_title= 'My Mod Name'
LIMIT 1;
DELETE FROM configuration WHERE configuration_group_id = @configuration_group_id;
DELETE FROM configuration_group WHERE configuration_group_id = @configuration_group_id;

If the mod has never been installed before, there is no such configuration group, so you wind up deleting configuration group 0.

This produces the problem described in this thread:
http://www.zen-cart.com/forum/showthread.php?t=170483

To avoid this, just have a separate "uninstall.sql" file and don't include the cleanup statements in your install.sql file.

You can tell that configuration group 0 has been deleted by looking at a product with a text field in your catalog product info page. You'll see something like this:

<input type="text" name="id[TEXT_PREFIX72]" size="32" maxlength="300" value="" id="attrib-72-0" />

instead of something like this:

<input type="text" name="id[txt_72]" size="32" maxlength="300" value="" id="attrib-72-0" />

A better way to structure your SQL if you want to clean up before you add config entries (provided by @Numinix):

SELECT @configuration_group_id:=configuration_group_id
FROM configuration_group
WHERE configuration_group_title= 'YOUR-FEATURE-NAME'
LIMIT 1;
DELETE FROM configuration WHERE configuration_group_id = @configuration_group_id AND configuration_group_id != 0;
DELETE FROM configuration_group WHERE configuration_group_id = @configuration_group_id AND configuration_group_id != 0;

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

5 Dec 2013, 12:40 AM
#2
numinix avatar

numinix

Totally Zenned

Join Date:
Apr 2007
Location:
Vancouver, Canada
Posts:
1,572
Plugin Contributions:
60

Re: Mod Authors: Please read if you are creating install.sql files

Please also do not blindly insert values into the configuration table, or any table for that matter. Always specify the column names.

Good example:

INSERT INTO configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, use_function, set_function) VALUES (NULL, 'Version', 'CSFB_VERSION', '1.0.0', 'Version installed:', " . $configuration_group_id . ", 0, NOW(), NULL, NULL);

Bad Example:

INSERT INTO configuration VALUES (NULL, 'Version', 'CSFB_VERSION', '1.0.0', 'Version  installed:', " . $configuration_group_id . ", 0, NOW(), NULL, NULL);
1 Dec 2014, 12:42 AM
#3
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,760
Plugin Contributions:
56

Re: Mod Authors: Please read if you are creating install.sql files

This is still a requirement, and I'm still seeing mods that come in that haven't done this. Please be sure to double check your mod!

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.