News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Mod Guidlines? - Upgrading

Started by brianjw, December 08, 2007, 11:40:00 AM

Previous topic - Next topic

Rumbaar

Well, for me, just because some other mods don't do it shouldn't mean it shouldn't be done for a 'proper' installation and removal process.

But I do know of mods that do a complete install and removal (including db modifications).  I haven't looked at all mods, but I keep coming back to the very well written MySpace Field mod (which I'm sure all snork13's are).  It's clean, clear and is very detailed in it's coding.  It does install DB mod's and removes that change upon un-installation, all in one complete package.

I personally would strive for that type of mod install and un-installation.  But each their own.



For any mod you have the Total Downloads: *** field that displays how many times it's been download.  Is that what you mean?
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

brianjw

Well, I own a package server...

It has one mod on it now, and soon hopefully to be adding more... but in the package-server...
Meaning packages.xml (download the package-sdk / it has this stuff in it), I'd like it to list
Total Downloads: # per mod right under it, above it or, in between all the mod info in the package server.

brianjw

PS: Package-SDK can be found in a link on the modsite i think...

karlbenson

Indeed, looking at a mod created by a person on the team(ex-team) can be useful.

The only comment I'd make about that myspace mod and its mysql/db changes is that it doesnt check the column already exists before inserting it.
Ok it may uninstall the column on uninstall, but imagine.

User has the mod installed.
User makes some changes and royally screws up his files.
User replaces all his templates files with fresh copies (from backup)
The column for the mod is still installed, but the mod isnt.
User tries to reinstall the mod, gets error as duplicate column.

Solution

$result = db_query("SHOW COLUMNS FROM {$db_prefix}members LIKE 'MYSPACE'", __FILE__, __LINE__);
if(mysql_num_rows($result) == 0)
{
db_query("
ALTER TABLE {$db_prefix}members ADD COLUMN
MYSPACE VARCHAR(50) NOT NULL default '',
TYPE=MyISAM", __FILE__, __LINE__);
}

Rumbaar

That is true, though I wasn't comparing the actual code, but the functionality of the overall installation package.  At least he uses $db_prefix and not hard code it to smf_, which I've seen too often :)
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

karlbenson

Also if your interested in the specs of the package-info and install files.

Checkout
http://www.simplemachines.org/xml

Rumbaar

I get a 403 Forbidden for that link, does it work for your karlbenson?
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

karlbenson

hmmm, it was a directory. I guess they made it private, although you can still view the files.

http://www.simplemachines.org/xml/package-info
http://www.simplemachines.org/xml/modification

Rumbaar

Ah yes.   When they moved those files weren't even accessible for a period of time.  Might be various permission issues still being sort out after the move.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

brianjw

Dang, those files are like, a different language... well they are but there just really hard to understand. :o

brianjw

Ok, now that my mod has been approved... I would like to make the GoogleMap_uninstall.zip file...
How would I reverse, this code:

<?php
/*******************************************************************************
This is a simplified script to add settings into SMF.

ATTENTION: If you are trying to INSTALL this package, please access
it directly, with a URL like the following:
http://www.yourdomain.tld/forum/add_settings.php (or similar.)

================================================================================

This script can be used to add new settings into the database for use
with SMF's $modSettings array.  It is meant to be run either from the
package manager or directly by URL.

*******************************************************************************/

// Set the below to true to overwrite already existing settings with the defaults. (not recommended.)
$overwrite_old_settings false;

// List settings here in the format: setting_key => default_value.  Escape any "s. (" => \")
$mod_settings = array(
'googleMapsEnable' => '0',
'googleMapsEnableLegend' => '1',
'googleMapsKey' => '',
'googleMapsPinGender' => '1',
'googleMapsPinNumber' => '250',
    
'googleMapsType' => 'G_HYBRID_TYPE',
    
'googleMapsDefaultLat' => '0.00000000000',
    
'googleMapsDefaultLong' => '0.00000000000',
    
'googleMapsDefaultZoom' => '1',
    
'googleMapsEnableClusterer' => '1',
    
'googleMapsMinMarkerCluster' => '5',
    
'googleMapsMaxVisMarker' => '150',
    
'googleMapsMaxNumClusters' => '5',
    
'googleMapsMaxLinesCluster' => '10',
);

/******************************************************************************/

// If SSI.php is in the same place as this file, and SMF isn't defined, this is being run standalone.
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
// Hmm... no SSI.php and no SMF?
elseif (!defined('SMF'))
die('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');

// Turn the array defined above into a string of MySQL data.
$string '';
foreach (
$mod_settings as $k => $v)
$string .= '
(\'' 
$k '\', \'' $v '\'),';

// Sorted out the array defined above - now insert the data!
if ($string != '')
$result db_query("
. ($overwrite_old_settings 'REPLACE' 'INSERT IGNORE') . " INTO {$db_prefix}settings
(variable, value)
VALUES" 
substr($string0, -1), __FILE____LINE__);

// Uh-oh spaghetti-oh!
if ($result === false)
echo '<b>Error:</b> Database modifications failed!';

//Ok now the above is done... lets see if we can alter the members table to contain latitude and longitude
//First though, lets check to see if we are in need of to do this
$latlongexist 0;
$result db_query("SHOW COLUMNS FROM {$db_prefix}members"__FILE____LINE__);
while (
$row mysql_fetch_array($resultMYSQL_ASSOC)) {
if (($row['Field'] == "longitude") && ($row['Type'] == "decimal(18,15)") && ($row['Null'] == "YES"))
$latlongexist++;
if (($row['Field'] == "latitude") && ($row['Type'] == "decimal(18,15)") && ($row['Null'] == "YES"))
$latlongexist++;
}
//Ok we just checked the table the hard way and well if 2 we have things, if 0 we dont, if 1 wtf....
if ($latlongexist != 2)
$result db_query("ALTER TABLE {$db_prefix}members ADD longitude DECIMAL( 18, 15 ) NULL , ADD latitude DECIMAL( 18, 15 ) NULL"__FILE____LINE__);

// Initialize the groups array with 'ungrouped members' (ID: 0).
$groups = array(0);

// Get all the non-postcount based groups.
$request db_query("
SELECT ID_GROUP
FROM 
{$db_prefix}membergroups
WHERE minPosts = -1"
__FILE____LINE__);
while ($row mysql_fetch_assoc($request))
$groups[] = $row['ID_GROUP'];

// Give them all their new permission.
$request db_query("
INSERT IGNORE INTO 
{$db_prefix}permissions
(permission, ID_GROUP, addDeny)
VALUES
('googleMap_view', " 
implode(", 1),
            ('googleMap_view', "
$groups) . ", 1)"__FILE____LINE__);

   
// Give them all their new permission.
$request db_query("
INSERT IGNORE INTO 
{$db_prefix}permissions
(permission, ID_GROUP, addDeny)
VALUES
('googleMap_place', " 
implode(", 1),
            ('googleMap_place', "
$groups) . ", 1)"__FILE____LINE__);

   
// Delete our package server if there is one.
   
$request db_query("
       DELETE FROM 
{$db_prefix}package_servers WHERE name = 'Gamerz Garage'"__FILE____LINE__);
      
   
// Install our package server.
   
$request db_query("
      INSERT INTO 
{$db_prefix}package_servers (name,url)VALUES('Gamerz Garage','http://www.gamerzgarage.com/mods')"__FILE____LINE__);

?>


into a remove_settings.php (im not very good with db...)

brianjw

SleePy

Jeremy D ~ Site Team / SMF Developer ~ GitHub Profile ~ Join us on IRC @ Libera.chat/#smf ~ Support the SMF Support team!

Advertisement: