예제 #1
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;
 }
예제 #2
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;
}
예제 #3
0
function xoops_module_update_smartpartner($module)
{
    include_once XOOPS_ROOT_PATH . "/modules/" . $module->getVar('dirname') . "/include/functions.php";
    include_once XOOPS_ROOT_PATH . "/modules/smartobject/class/smartdbupdater.php";
    $dbupdater = new SmartobjectDbupdater();
    ob_start();
    $dbVersion = smartpartner_GetMeta('version');
    $dbupdater = new SmartobjectDbupdater();
    echo "<code>" . _SDU_UPDATE_UPDATING_DATABASE . "<br />";
    //smartpartner_create_upload_folders();
    // db migrate version = 3
    $newDbVersion = 3;
    if ($dbVersion < $newDbVersion) {
        echo "Database migrate to version " . $newDbVersion . "<br />";
        $table = new SmartDbTable('smartpartner_partner');
        $table->addNewField('email_priv', " tinyint(1) NOT NULL default '0'");
        $table->addNewField('phone_priv', " tinyint(1) NOT NULL default '0'");
        $table->addNewField('adress_priv', " tinyint(1) NOT NULL default '0'");
        if (!$dbupdater->updateTable($table)) {
            /**
             * @todo trap the errors
             */
        }
        unset($table);
    }
    // db migrate version =4
    $newDbVersion = 4;
    if ($dbVersion < $newDbVersion) {
        echo "Database migrate to version " . $newDbVersion . "<br />";
        //create new tables
        // Create table smartpartner_categories
        $table = new SmartDbTable('smartpartner_categories');
        if (!$table->exists()) {
            $table->setStructure("\r\n\t\t\t  `categoryid` int(11) NOT NULL auto_increment,\r\n\t\t\t  `parentid` int(11) NOT NULL default '0',\r\n\t\t\t  `name` varchar(100) NOT NULL default '',\r\n\t\t\t  `description` text NOT NULL,\r\n\t\t\t  `image` varchar(255) NOT NULL default '',\r\n\t\t\t  `total` int(11) NOT NULL default '0',\r\n\t\t\t  `weight` int(11) NOT NULL default '1',\r\n\t\t\t  `created` int(11) NOT NULL default '0',\r\n\t\t\t  PRIMARY KEY  (`categoryid`)\r\n\t\t\t");
            if (!$dbupdater->updateTable($table)) {
                /**
                 * @todo trap the errors
                 */
            }
        }
        // Create table smartpartner_partner_cat_link
        $table = new SmartDbTable('smartpartner_partner_cat_link');
        if (!$table->exists()) {
            $table->setStructure("\r\n\t\t\t  `partner_cat_linkid` int(11) NOT NULL auto_increment,\r\n\t\t\t  `categoryid` int(11) NOT NULL default '0',\r\n\t\t\t  `partnerid` int(11) NOT NULL default '0',\r\n\t\t\t   PRIMARY KEY  (`partner_cat_linkid`)\r\n\t\t\t");
            if (!$dbupdater->updateTable($table)) {
                /**
                 * @todo trap the errors
                 */
            }
        }
        // Create table smartpartner_offer
        $table = new SmartDbTable('smartpartner_offer');
        if (!$table->exists()) {
            $table->setStructure("\r\n\t\t\t   `offerid` int(11) NOT NULL auto_increment,\r\n\t\t\t  `partnerid` int(11) NOT NULL default '0',\r\n\t\t\t  `title` varchar(255) NOT NULL default '',\r\n\t\t\t  `description` TEXT NOT NULL,\r\n\t\t\t  `url` varchar(150) default '',\r\n\t\t\t  `image` varchar(150) NOT NULL default '',\r\n\t\t\t  `date_sub` int(11) NOT NULL default '0',\r\n\t\t\t  `date_pub` int(11) NOT NULL default '0',\r\n\t\t\t  `date_end` int(11) NOT NULL default '0',\r\n\t\t\t  `status` int(10) NOT NULL default '-1',\r\n\t\t\t  `weight` int(1) NOT NULL default '0',\r\n\t\t\t  `dohtml` int(1) NOT NULL default '1',\r\n\t\t\t  PRIMARY KEY  (`offerid`)\r\n\t\t\t");
            if (!$dbupdater->updateTable($table)) {
                /**
                 * @todo trap the errors
                 */
            }
        }
        // Create table smartpartner_offer
        $table = new SmartDbTable('smartpartner_files');
        if (!$table->exists()) {
            $table->setStructure("\r\n\t\t\t  `fileid` int(11) NOT NULL auto_increment,\r\n\t\t\t  `id` int(11) NOT NULL default '0',\r\n\t\t\t  `name` varchar(255) NOT NULL default '',\r\n\t\t\t  `description` TEXT NOT NULL,\r\n\t\t\t  `filename` varchar(255) NOT NULL default '',\r\n\t\t\t  `mimetype` varchar(64) NOT NULL default '',\r\n\t\t\t  `uid` int(6) default '0',\r\n\t\t\t  `datesub` int(11) NOT NULL default '0',\r\n\t\t\t  `status` int(1) NOT NULL default '-1',\r\n\t\t\t  `notifypub` tinyint(1) NOT NULL default '1',\r\n\t\t\t  `counter` int(8) unsigned NOT NULL default '0',\r\n\t\t\t  PRIMARY KEY  (`fileid`)\r\n\t\t\t");
            if (!$dbupdater->updateTable($table)) {
                /**
                 * @todo trap the errors
                 */
            }
        }
        //loop in partners to insert cat_links in partner_cat_link table
        $smartparner_partner_handler = xoops_getModuleHandler('partner', 'smartpartner');
        $smartparner_partner_cat_link_handler = xoops_getModuleHandler('partner_cat_link', 'smartpartner');
        $moduleperm_handler =& xoops_gethandler('groupperm');
        $module_handler =& xoops_gethandler('module');
        $module = $module_handler->getByDirname('smartpartner');
        $groupsArray = $moduleperm_handler->getGroupIds('module_read', $module->mid(), 1);
        $sql = 'SELECT id, categoryid from ' . $smartparner_partner_handler->table;
        $records = $smartparner_partner_handler->query($sql);
        foreach ($records as $record) {
            if ($record['categoryid'] != 0) {
                $new_link = $smartparner_partner_cat_link_handler->create();
                $new_link->setVar('partnerid', $record['id']);
                $new_link->setVar('categoryid', $record['categoryid']);
                $smartparner_partner_cat_link_handler->insert($new_link);
                unset($new_link);
            }
            foreach ($groupsArray as $group) {
                $moduleperm_handler->addRight('full_view', $record['id'], $group, $module->mid());
            }
        }
        //drop cat_id in partner table
        $table = new SmartDbTable('smartpartner_partner');
        $table->addNewField('last_update', " int(11) NOT NULL default '0'");
        $table->addNewField('showsummary', " tinyint(1) NOT NULL default '0'");
        $table->addDropedField('categoryid');
        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;
    }
    smartpartner_SetMeta("version", isset($newDbVersion) ? $newDbVersion : 0);
    //Set meta version to current
    return true;
}