예제 #1
0
/**
 * Execute SQL query
 *
 * @return void
 */
function dbExecute($sql, &$errorMsg = null)
{
    try {
        \Includes\Utils\Database::execute($sql);
    } catch (Exception $e) {
        $errorMsg = $e->getMessage();
    }
}
예제 #2
0
 /**
  * Write module info to DB
  *
  * @param string  $author              Module author
  * @param string  $name                Module name
  * @param boolean $isModulesFileExists Flag: true means that the installation process is going now OPTIONAL
  *
  * @return void
  */
 public static function switchModule($author, $name, $isModulesFileExists = false)
 {
     // Short names
     $condition = ' WHERE author = ? AND name = ?';
     $table = static::getTableName();
     $module = static::getActualName($author, $name);
     // Versions
     $majorVersion = static::callModuleMethod($module, 'getMajorVersion');
     $minorVersion = static::callModuleMethod($module, 'getMinorVersion');
     // Reset existing settings
     $query = 'UPDATE ' . $table . ' SET enabled = ?, installed = ?' . $condition;
     \Includes\Utils\Database::execute($query, array(0, 0, $author, $name));
     // Search for module
     $fields = array('moduleID');
     $condition .= ' AND fromMarketplace = ?';
     if (!$isModulesFileExists) {
         $fields[] = 'yamlLoaded';
     }
     $query = 'SELECT ' . implode(', ', $fields) . ' FROM ' . $table . $condition . ' AND majorVersion = ? AND minorVersion = ?';
     $moduleRows = \Includes\Utils\Database::fetchAll($query, array($author, $name, 0, $majorVersion, $minorVersion));
     $needToLoadYaml = false;
     // If found in DB
     if ($moduleRows) {
         $moduleID = intval($moduleRows[0]['moduleID']);
         $yamlLoaded = intval($moduleRows[0]['yamlLoaded']);
         $moduleName = static::callModuleMethod($module, 'getModuleName');
         $moduleDesc = static::callModuleMethod($module, 'getDescription');
         $params = array('enabled = ?', 'installed = ?', 'moduleName = ?', 'description = ?');
         $data = array(intval(static::isActiveModule($module)), 1, $moduleName, $moduleDesc, $moduleID);
         if (!$yamlLoaded && static::isActiveModule($module)) {
             $params[] = 'yamlLoaded = ?';
             $data = array(intval(static::isActiveModule($module)), 1, $moduleName, $moduleDesc, 1, $moduleID);
             $needToLoadYaml = true;
         }
         $query = 'UPDATE ' . $table . ' SET ' . implode(', ', $params) . ' WHERE moduleID = ?';
     } else {
         $data = static::getModuleDataFromClass($author, $name);
         if ($data['enabled']) {
             $data['yamlLoaded'] = 1;
             $needToLoadYaml = true;
         }
         $query = 'REPLACE INTO ' . $table . ' SET ' . implode(' = ?,', array_keys($data)) . ' = ?';
     }
     if (static::isActiveModule($module) && $needToLoadYaml && !$isModulesFileExists) {
         static::addModuleYamlFile($author, $name);
     }
     // Save changes in DB
     \Includes\Utils\Database::execute($query, array_values($data));
 }
예제 #3
0
// vim: set ts=4 sw=4 sts=4 et:
/**
 * LiteCommerce
 * 
 * NOTICE OF LICENSE
 * 
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to licensing@litecommerce.com so we can send you a copy immediately.
 * 
 * PHP version 5.3.0
 * 
 * @category  LiteCommerce
 * @author    Creative Development LLC <*****@*****.**> 
 * @copyright Copyright (c) 2011 Creative Development LLC <*****@*****.**>. All rights reserved
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 * @link      http://www.litecommerce.com/
 */
return function () {
    // Update tables structure to avoid categories and products images loss
    $prefix = \XLite\Core\Database::getInstance()->getTablePrefix();
    $queries = array("ALTER TABLE `{$prefix}category_images` DROP FOREIGN KEY `{$prefix}category_images_ibfk_1`;", "ALTER TABLE `{$prefix}category_images` CHANGE `id` `category_id` int(10) unsigned DEFAULT NULL;", "ALTER TABLE `{$prefix}category_images` CHANGE `image_id` `id` int(10) unsigned NOT NULL AUTO_INCREMENT;", "ALTER TABLE `{$prefix}product_images` DROP FOREIGN KEY `{$prefix}product_images_ibfk_1`;", "ALTER TABLE `{$prefix}product_images` CHANGE `id` `product_id` int(10) unsigned DEFAULT NULL;", "ALTER TABLE `{$prefix}product_images` CHANGE `image_id` `id` int(10) unsigned NOT NULL AUTO_INCREMENT;");
    foreach ($queries as $query) {
        \Includes\Utils\Database::execute($query);
    }
};