Esempio n. 1
0
function xoops_module_update_smartobject($module)
{
    ob_start();
    $dbVersion = smart_GetMeta('version', 'smartobject');
    if (!$dbVersion) {
        $dbVersion = 0;
    }
    $dbupdater = new SmartobjectDbupdater();
    echo "<code>" . _SDU_UPDATE_UPDATING_DATABASE . "<br />";
    // db migrate version = 1
    $newDbVersion = 1;
    if ($dbVersion < $newDbVersion) {
        echo "Database migrate to version " . $newDbVersion . "<br />";
        // Create table smartobject_link
        $table = new SmartDbTable('smartobject_link');
        if (!$table->exists()) {
            $table->setStructure("CREATE TABLE %s (\n\t\t\t  `linkid` int(11) NOT NULL auto_increment,\n\t\t\t  `from_uid` int(11) NOT NULL default '0',\n\t\t\t  `from_email` varchar(255) NOT NULL default '',\n\t\t\t  `from_name` varchar(255) NOT NULL default '',\n\t\t\t  `to_uid` int(11) NOT NULL default '0',\n\t\t\t  `to_email` varchar(255) NOT NULL default '',\n\t\t\t  `to_name` varchar(255) NOT NULL default '',\n\t\t\t  `link` varchar(255) NOT NULL default '',\n\t\t\t  `subject` varchar(255) NOT NULL default '',\n\t\t\t  `body` TEXT NOT NULL,\n\t\t\t  `mid` int(11) NOT NULL default '0',\n\t\t\t  `mid_name` varchar(255) NOT NULL default '',\n\n\t\t\t  PRIMARY KEY  (`linkid`)\n\t\t\t) TYPE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;");
            if (!$dbupdater->updateTable($table)) {
                /**
                 * @todo trap the errors
                 */
            }
        }
        unset($table);
        $table = new SmartDbTable('smartobject_link');
        if (!$table->fieldExists('date')) {
            $table->addNewField('date', "int(11) NOT NULL default '0'");
            if (!$dbupdater->updateTable($table)) {
                /**
                 * @todo trap the errors
                 */
            }
        }
        unset($table);
        // Create table smartobject_tag
        $table = new SmartDbTable('smartobject_tag');
        if (!$table->exists()) {
            $table->setStructure("CREATE TABLE %s (\n\t\t      `tagid` int(11) NOT NULL auto_increment,\n\t\t\t  `name` varchar(255) NOT NULL default '',\n\t\t\t  `description` TEXT NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`)\n\t\t\t) TYPE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;");
            if (!$dbupdater->updateTable($table)) {
                /**
                 * @todo trap the errors
                 */
            }
        }
        // Create table smartobject_tag_text
        $table = new SmartDbTable('smartobject_tag_text');
        if (!$table->exists()) {
            $table->setStructure("CREATE TABLE %s (\n\t\t\t  `tagid` int(11) NOT NULL default 0,\n\t\t\t  `language` varchar(255) NOT NULL default '',\n\t\t\t  `value` TEXT NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`, `language`)\n\t\t\t) TYPE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;");
            if (!$dbupdater->updateTable($table)) {
                /**
                 * @todo trap the errors
                 */
            }
        }
        // Create table smartobject_adsense
        $table = new SmartDbTable('smartobject_adsense');
        if (!$table->exists()) {
            $table->setStructure("\n  `adsenseid` int(11) NOT NULL auto_increment,\n  `format` VARCHAR(100) NOT NULL,\n  `description` TEXT NOT NULL,\n  `style` TEXT NOT NULL,\n  `border_color` varchar(6) NOT NULL default '',\n  `background_color` varchar(6) NOT NULL default '',\n  `link_color` varchar(6) NOT NULL default '',\n  `url_color` varchar(6) NOT NULL default '',\n  `text_color` varchar(6) NOT NULL default '',\n  `client_id` varchar(100) NOT NULL default '',\n  `tag` varchar(50) NOT NULL default '',\n  PRIMARY KEY  (`adsenseid`)\n\t\t\t");
        }
        if (!$dbupdater->updateTable($table)) {
            /**
             * @todo trap the errors
             */
        }
    }
    // db migrate version = 2
    $newDbVersion = 2;
    if ($dbVersion < $newDbVersion) {
        echo "Database migrate to version " . $newDbVersion . "<br />";
        // Create table smartobject_adsense
        $table = new SmartDbTable('smartobject_rating');
        if (!$table->exists()) {
            $table->setStructure("\n  `ratingid` int(11) NOT NULL auto_increment,\n  `dirname` VARCHAR(255) NOT NULL,\n  `item` VARCHAR(255) NOT NULL,\n  `itemid` int(11) NOT NULL,\n  `uid` int(11) NOT NULL,\n  `rate` int(1) NOT NULL,\n  `date` int(11) NOT NULL,\n  PRIMARY KEY  (`ratingid`),\n  UNIQUE (`dirname`, `item`, `itemid`, `uid`)\n\t\t\t");
        }
        if (!$dbupdater->updateTable($table)) {
            /**
             * @todo trap the errors
             */
        }
        // Create table smartobject_adsense
        $table = new SmartDbTable('smartobject_currency');
        $table->setData("2, 'EUR', 'Euro', '€', 0.65, 0");
        $table->setData("3, 'USD', 'American dollar', '\$', 0.9, 0");
        $table->setData("1, 'CAD', 'Canadian dollar', '\$', 1, 1");
        if (!$dbupdater->updateTable($table)) {
            /**
             * @todo trap the errors
             */
        }
    }
    // db migrate version = 3
    $newDbVersion = 3;
    if ($dbVersion < $newDbVersion) {
        echo "Database migrate to version " . $newDbVersion . "<br />";
        // Create table smartobject_adsense
        $table = new SmartDbTable('smartobject_customtag');
        if (!$table->exists()) {
            $table->setStructure("\n\t\t\t  `customtagid` int(11) NOT NULL auto_increment,\n\t\t\t  `name` VARCHAR(255) NOT NULL,\n\t\t\t  `description` TEXT NOT NULL,\n\t\t\t  `content` TEXT NOT NULL,\n\t\t\t  `language` TEXT NOT NULL,\n\t\t\t  PRIMARY KEY  (`customtagid`)\n\t\t\t");
        }
        if (!$dbupdater->updateTable($table)) {
            /**
             * @todo trap the errors
             */
        }
    }
    // db migrate version = 4
    $newDbVersion = 4;
    if ($dbVersion < $newDbVersion) {
        echo "Database migrate to version " . $newDbVersion . "<br />";
        // Create table smartobject_adsense
        $table = new SmartDbTable('smartobject_currency');
        if (!$table->exists()) {
            $table->setStructure("\n\t\t\t  `currencyid` int(11) NOT NULL auto_increment,\n\t\t\t  `iso4217` VARCHAR(5) NOT NULL,\n\t\t\t  `name` VARCHAR(255) NOT NULL,\n\t\t\t  `symbol`  VARCHAR(1) NOT NULL,\n\t\t\t  `rate` float NOT NULL,\n\t\t\t  `default_currency` int(1) NOT NULL,\n\t\t\t  PRIMARY KEY  (`currencyid`)\n\t\t\t");
        }
        if (!$dbupdater->updateTable($table)) {
            /**
             * @todo trap the errors
             */
        }
    }
    // db migrate version = 6
    $newDbVersion = 6;
    if ($dbVersion < $newDbVersion) {
        echo "Database migrate to version " . $newDbVersion . "<br />";
    }
    $newDbVersion = 7;
    if ($dbVersion < $newDbVersion) {
        echo "Database migrate to version " . $newDbVersion . "<br />";
        // Create table smartobject_link
        $table = new SmartDbTable('smartobject_file');
        if (!$table->exists()) {
            $table->setStructure("\n\t\t\t  `fileid` int(11) NOT NULL auto_increment,\n\t\t\t  `caption` varchar(255) collate latin1_general_ci NOT NULL,\n\t\t\t  `url` varchar(255) collate latin1_general_ci NOT NULL,\n\t\t\t  `description` text collate latin1_general_ci NOT NULL,\n\t\t\t   PRIMARY KEY  (`fileid`)\n\t\t\t");
            if (!$dbupdater->updateTable($table)) {
                /**
                 * @todo trap the errors
                 */
            }
        }
        unset($table);
        $table = new SmartDbTable('smartobject_urllink');
        if (!$table->exists()) {
            $table->setStructure("\n\t\t\t  `urllinkid` int(11) NOT NULL auto_increment,\n\t\t\t  `caption` varchar(255) collate latin1_general_ci NOT NULL,\n\t\t\t  `url` varchar(255) collate latin1_general_ci NOT NULL,\n\t\t\t  `description` text collate latin1_general_ci NOT NULL,\n\t\t\t  `target` varchar(10) collate latin1_general_ci NOT NULL,\n \t\t\t   PRIMARY KEY  (`urllinkid`)\n\t\t\t");
            if (!$dbupdater->updateTable($table)) {
                /**
                 * @todo trap the errors
                 */
            }
        }
        unset($table);
    }
    echo "</code>";
    $feedback = ob_get_clean();
    if (method_exists($module, "setMessage")) {
        $module->setMessage($feedback);
    } else {
        echo $feedback;
    }
    smart_SetMeta("version", $newDbVersion, "smartobject");
    //Set meta version to current
    return true;
}
Esempio n. 2
0
 function moduleUpgrade(&$module)
 {
     $dirname = $module->getVar('dirname');
     ob_start();
     $table = new SmartDbTable($dirname . '_meta');
     if (!$table->exists()) {
         $table->setStructure("\n\t\t\t  `metakey` varchar(50) NOT NULL default '',\n\t\t\t  `metavalue` varchar(255) NOT NULL default '',\n\t\t\t  PRIMARY KEY (`metakey`)");
         $table->setData("'version',0");
         if (!$this->updateTable($table)) {
             /**
              * @todo trap the errors
              */
         }
     }
     $dbVersion = smart_GetMeta('version', $dirname);
     if (!$dbVersion) {
         $dbVersion = 0;
     }
     $newDbVersion = constant(strtoupper($dirname . '_db_version')) ? constant(strtoupper($dirname . '_db_version')) : 0;
     echo 'Database version : ' . $dbVersion . '<br />';
     echo 'New database version : ' . $newDbVersion . '<br />';
     if ($newDbVersion > $dbVersion) {
         for ($i = $dbVersion + 1; $i <= $newDbVersion; $i++) {
             $upgrade_function = $dirname . '_db_upgrade_' . $i;
             if (function_exists($upgrade_function)) {
                 $upgrade_function();
             }
         }
     }
     echo "<code>" . _SDU_UPDATE_UPDATING_DATABASE . "<br />";
     // if there is a function to execute for this DB version, let's do it
     //$function_
     $module_info = smart_getModuleInfo($dirname);
     $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']);
     echo "</code>";
     $feedback = ob_get_clean();
     if (method_exists($module, "setMessage")) {
         $module->setMessage($feedback);
     } else {
         echo $feedback;
     }
     smart_SetMeta("version", $newDbVersion, $dirname);
     //Set meta version to current
     return true;
 }