コード例 #1
0
ファイル: Main.php プロジェクト: kirkbauer2/kirkxc
 /**
  * Execute certain hook handle
  *
  * @return void
  */
 public function executeHookHandler()
 {
     $list = \Includes\Decorator\Plugin\Doctrine\Utils\FixturesManager::getFixtures();
     if ($list) {
         \Includes\Utils\Operator::showMessage('', true, false);
         foreach ($list as $fixture) {
             $message = '...Load ' . substr($fixture, strlen(LC_DIR_ROOT));
             \Includes\Utils\Operator::showMessage($message, true, true);
             \Includes\Decorator\Utils\CacheManager::logMessage(PHP_EOL);
             \Includes\Decorator\Utils\CacheManager::logMessage($message);
             if (static::isYAML($fixture)) {
                 // Load YAML fixture
                 \XLite\Core\Database::getInstance()->loadFixturesFromYaml($fixture);
             } else {
                 // Load SQL queries
                 \Includes\Utils\Database::uploadSQLFromFile($fixture);
             }
             \Includes\Decorator\Plugin\Doctrine\Utils\FixturesManager::removeFixtureFromList($fixture);
             if (\Includes\Decorator\Utils\CacheManager::isTimeExceeds(static::STEP_TTL)) {
                 break;
             }
         }
     }
     \Includes\Decorator\Utils\CacheManager::logMessage(PHP_EOL);
     \XLite\Core\Database::getEM()->clear();
 }
コード例 #2
0
ファイル: pre_upgrade.php プロジェクト: kirkbauer2/kirkxc
 */
return function () {
    $tablePrefix = \XLite::getInstance()->getOptions(array('database_details', 'table_prefix'));
    $tables = array('news' => 'id');
    foreach ($tables as $table => $tableKey) {
        $tableName = $tablePrefix . $table;
        $tableColumns = \XLite\Core\Database::getEM()->getConnection()->getSchemaManager()->listTableColumns($tableName);
        $found = false;
        foreach (array_keys($tableColumns) as $column) {
            if (strtolower($column) == 'cleanurl') {
                $found = true;
                break;
            }
        }
        if ($found) {
            $items = array();
            $query = 'SELECT ' . $tableKey . ', cleanURL FROM ' . $tableName;
            $result = \Includes\Utils\Database::fetchAll($query);
            if ($result) {
                foreach ($result as $data) {
                    if ($data['cleanURL']) {
                        $items[$data[$tableKey]] = $data['cleanURL'];
                    }
                }
                if ($items) {
                    \Includes\Utils\Operator::saveServiceYAML(LC_DIR_VAR . 'cleanURL.newsMessages.yaml', $items);
                }
            }
        }
    }
};
コード例 #3
0
ファイル: Settings.php プロジェクト: kingsj/core
 /**
  * Returns value by request
  *
  * @param string $name Type of value
  *
  * @return string
  */
 public function get($name)
 {
     $return = '';
     switch ($name) {
         case 'phpversion':
             $return = PHP_VERSION;
             break;
         case 'os_type':
             list($osType) = explode(' ', PHP_OS);
             $return = $osType;
             break;
         case 'mysql_server':
             $return = \Includes\Utils\Database::getDbVersion();
             break;
         case 'innodb_support':
             $return = \Includes\Utils\Database::isInnoDBSupported();
             break;
         case 'root_folder':
             $return = getcwd();
             break;
         case 'web_server':
             if (isset($_SERVER['SERVER_SOFTWARE'])) {
                 $return = $_SERVER['SERVER_SOFTWARE'];
             } else {
                 $return = '';
             }
             break;
         case 'xml_parser':
             ob_start();
             phpinfo(INFO_MODULES);
             $phpInfo = ob_get_contents();
             ob_end_clean();
             if (preg_match('/EXPAT.+>([\\.\\d]+)/mi', $phpInfo, $m)) {
                 $return = $m[1];
             } else {
                 $return = function_exists('xml_parser_create') ? 'found' : '';
             }
             break;
         case 'gdlib':
             if (!$this->is('GDLibLoaded')) {
                 $return = '';
             } else {
                 ob_start();
                 phpinfo(INFO_MODULES);
                 $phpInfo = ob_get_contents();
                 ob_end_clean();
                 if (preg_match('/GD.+>([\\.\\d]+)/mi', $phpInfo, $m)) {
                     $gdVersion = $m[1];
                 } else {
                     $gdVersion = @gd_info();
                     if (is_array($gdVersion) && isset($gdVersion['GD Version'])) {
                         $gdVersion = $gdVersion['GD Version'];
                     } else {
                         $gdVersion = 'unknown';
                     }
                 }
                 $return = 'found (' . $gdVersion . ')';
             }
             break;
         case 'core_version':
             $return = \XLite::getInstance()->getVersion();
             break;
         case 'libcurl':
             $libcurlVersion = curl_version();
             if (is_array($libcurlVersion)) {
                 $libcurlVersion = $libcurlVersion['version'];
             }
             $return = $libcurlVersion;
             break;
         case 'check_files':
             $result = array();
             $files = array();
             foreach ($files as $file) {
                 $mode = $this->getFilePermission($file);
                 $modeStr = $this->getFilePermissionStr($file);
                 $res = array('file' => $file, 'error' => '');
                 if (!is_file($file)) {
                     $res['error'] = 'does_not_exist';
                     $result[] = $res;
                     continue;
                 }
                 $perm = substr(sprintf('%o', @fileperms($file)), -4);
                 if ($perm != $modeStr) {
                     if (!@chmod($file, $mode)) {
                         $res['error'] = 'cannot_chmod';
                         $result[] = $res;
                         continue;
                     }
                 } else {
                     if ($this->getComplex('xlite.suMode') != 0) {
                         if (!@chmod($file, $mode)) {
                             $res['error'] = 'wrong_owner';
                             $result[] = $res;
                             continue;
                         }
                     }
                 }
                 $result[] = $res;
             }
             $return = $result;
             break;
             // :FIXME: checng to the constants
         // :FIXME: checng to the constants
         case 'check_dirs':
             $result = array();
             $dirs = array('var/run', 'var/log', 'var/html', 'var/backup', 'var/tmp', 'catalog', 'images', 'classes/modules', 'skins/default/en/modules', 'skins/admin/en/modules', 'skins/default/en/images/modules', 'skins/admin/en/images/modules', 'skins/mail/en/modules', 'skins/mail/en/images/modules');
             foreach ($dirs as $dir) {
                 $mode = $this->getDirPermission($dir);
                 $modeStr = $this->getDirPermissionStr($dir);
                 $res = array('dir' => $dir, 'error' => '', 'subdirs' => array());
                 if (!is_dir($dir)) {
                     $fullPath = '';
                     $path = explode('/', $dir);
                     foreach ($path as $sub) {
                         $fullPath .= $sub . '/';
                         if (!is_dir($fullPath) && @mkdir($fullPath, $mode) !== true) {
                             break;
                         }
                     }
                 }
                 if (!is_dir($dir)) {
                     $res['error'] = 'cannot_create';
                     $result[] = $res;
                     continue;
                 }
                 $perm = substr(sprintf('%o', @fileperms($dir)), -4);
                 if ($perm != $modeStr) {
                     if (!@chmod($dir, $mode)) {
                         $res['error'] = 'cannot_chmod';
                         $result[] = $res;
                         continue;
                     }
                 } else {
                     if ($this->getComplex('xlite.suMode') != 0 || strpos($dir, 'var') !== false) {
                         if (!@chmod($dir, $mode)) {
                             $res['error'] = 'wrong_owner';
                             $result[] = $res;
                             continue;
                         }
                     }
                 }
                 $subdirs = array();
                 if ('catalog' != $dir && 'images' != $dir) {
                     $this->checkSubdirs($dir, $subdirs);
                 }
                 if (!empty($subdirs)) {
                     $res['error'] = 'cannot_chmod_subdirs';
                     $res['subdirs'] = $subdirs;
                     $result[] = $res;
                     continue;
                 }
                 $result[] = $res;
             }
             $return = $result;
             break;
         default:
             $return = parent::get($name);
     }
     return $return;
 }
コード例 #4
0
ファイル: install.php プロジェクト: kirkbauer2/kirkxc
/**
 * Check MySQL version: returns false only if version is gathered and it isn't suit
 *
 * @param string   $errorMsg    Error message if checking failed
 * @param string   $value       Actual value of the checked parameter
 * @param resource $isConnected MySQL connection link OPTIONAL
 *
 * @return boolean
 */
function checkMysqlVersion(&$errorMsg, &$value, $isConnected = false)
{
    global $isDBConnected;
    $result = true;
    $value = xtr('unknown');
    $pdoErrorMsg = '';
    $version = false;
    if (defined('DB_URL')) {
        // Connect via PDO and get DB version
        $data = unserialize(constant('DB_URL'));
        // Support of Drupal 6 $db_url
        if (!is_array($data)) {
            $data = parseDbURL(constant('DB_URL'));
        }
        $isConnected = dbConnect($data, $pdoErrorMsg);
        if (!$isConnected) {
            $errorMsg = xtr('Can\'t connect to MySQL server') . (!empty($pdoErrorMsg) ? ': ' . $pdoErrorMsg : '');
        }
    }
    if ($isConnected || $isDBConnected) {
        try {
            $version = \Includes\Utils\Database::getDbVersion();
        } catch (Exception $e) {
            $pdoErrorMsg = $e->getMessage();
        }
        // Check version
        if ($version) {
            x_install_log(xtr('MySQL version: ' . $version));
            if (version_compare($version, constant('LC_MYSQL_VERSION_MIN')) < 0) {
                $result = false;
                $errorMsg = xtr('MySQL version must be :minver as a minimum.', array(':minver' => constant('LC_MYSQL_VERSION_MIN')));
            } else {
                // Check for InnoDb support
                if (!\Includes\Utils\Database::isInnoDBSupported()) {
                    $result = false;
                    $errorMsg = xtr('MySQL server doesn\'t support InnoDB engine. It is required for X-Cart operation');
                }
            }
        } else {
            $errorMsg = xtr('Cannot get the MySQL server version') . (!empty($pdoErrorMsg) ? ' : ' . $pdoErrorMsg : '.');
        }
    }
    $value = $version;
    return $result;
}
コード例 #5
0
ファイル: DbRestore.php プロジェクト: kirkbauer2/kirkxc
 /**
  * Common restore database method used by actions
  *
  * @param mixed $sqlFile File with SQL data for loading into database
  *
  * @return boolean
  */
 protected function restoreDatabase($sqlFile)
 {
     $result = false;
     // File to create temporary backup to be able rollback database
     $backupSQLFile = LC_DIR_BACKUP . sprintf('sqldump.backup.%d.sql', \XLite\Core\Converter::time());
     // Make the process of restoring database verbose
     $verbose = true;
     // Start
     $this->startDump();
     // Making the temporary backup file
     \Includes\Utils\Operator::flush(static::t('Making backup of the current database state ... '), true);
     $result = \XLite\Core\Database::getInstance()->exportSQLToFile($backupSQLFile, $verbose);
     \Includes\Utils\Operator::flush(static::t('done') . LC_EOL . LC_EOL, true);
     // Loading specified SQL-file to the database
     \Includes\Utils\Operator::flush(static::t('Loading the database from file .'));
     $result = \Includes\Utils\Database::uploadSQLFromFile($sqlFile, $verbose);
     $restore = false;
     if ($result) {
         // If file has been loaded into database successfully
         $message = static::t('Database restored successfully!');
         // Prepare the cache rebuilding
         \XLite::setCleanUpCacheFlag(true);
     } else {
         // If an error occured while loading file into database
         $message = static::t('The database has not been restored because of the errors');
         $restore = true;
     }
     // Display the result message
     \Includes\Utils\Operator::flush(' ' . static::t('done') . LC_EOL . LC_EOL . $message . LC_EOL);
     if ($restore) {
         // Restore database from temporary backup
         \Includes\Utils\Operator::flush(LC_EOL . static::t('Restoring database from the backup .'));
         \Includes\Utils\Database::uploadSQLFromFile($backupSQLFile, $verbose);
         \Includes\Utils\Operator::flush(' ' . static::t('done') . LC_EOL . LC_EOL);
     }
     // Display Javascript to cancel scrolling page to bottom
     func_refresh_end();
     // Display the bottom HTML part
     $this->displayPageFooter();
     // Remove temporary backup file
     unlink($backupSQLFile);
     return $result;
 }
コード例 #6
0
ファイル: EntityManager.php プロジェクト: kirkbauer2/kirkxc
 /**
  * Retur DSN as params array
  *
  * @return array
  */
 protected static function getDSN()
 {
     return \Includes\Utils\Database::getConnectionParams(true) + array('driver' => 'pdo_mysql');
 }
コード例 #7
0
ファイル: ModulesManager.php プロジェクト: kirkbauer2/kirkxc
 /**
  * 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));
 }
コード例 #8
0
ファイル: functions.php プロジェクト: kirkbauer2/kirkxc
/**
 * Execute SQL query
 *
 * @return void
 */
function dbExecute($sql, &$errorMsg = null)
{
    try {
        \Includes\Utils\Database::execute($sql);
    } catch (Exception $e) {
        $errorMsg = $e->getMessage();
    }
}
コード例 #9
0
ファイル: post_upgrade.php プロジェクト: kingsj/core
// 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);
    }
};
コード例 #10
0
ファイル: Category.php プロジェクト: kirkbauer2/kirkxc
 /**
  * Simplified search for categories data
  *
  * @return array
  */
 protected function getCategoriesRawData()
 {
     $fields = array('c.category_id', 'c.parent_id', 'c.lpos', 'c.rpos', 'c.depth', 'c.pos', 'c.enabled', 'qf.subcategories_count_all', 'qf.subcategories_count_enabled');
     $query = 'SELECT ' . implode(',', $fields) . ' FROM ' . $this->getTableName() . ' c ' . ' LEFT JOIN ' . \XLite\Core\Database::getRepo('XLite\\Model\\Category\\QuickFlags')->getTableName() . ' qf ON c.category_id = qf.category_id ' . ' ORDER BY c.category_id';
     return \Includes\Utils\Database::fetchAll($query);
 }