예제 #1
0
 */
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);
                }
            }
        }
    }
};
예제 #2
0
/**
 * Execute SQL query and return the result as an associated array
 *
 * @return array
 */
function dbFetchAll($sql, &$errorMsg = null)
{
    $result = null;
    try {
        $result = \Includes\Utils\Database::fetchAll($sql);
    } catch (Exception $e) {
        $errorMsg = $e->getMessage();
    }
    return $result;
}
예제 #3
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));
 }
예제 #4
0
 /**
  * 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);
 }