Esempio n. 1
0
/**
 * Alle Metafelder löschen, nicht das nach einem Import in der Parameter Tabelle
 * noch Datensätze zu Feldern stehen, welche nicht als Spalten in der
 * rex_article angelegt wurden!
 */
function rex_metainfo_cleanup($epOrParams)
{
    $params = $epOrParams instanceof rex_extension_point ? $epOrParams->getParams() : $epOrParams;
    // Cleanup nur durchführen, wenn auch die rex_article Tabelle neu angelegt wird
    if (isset($params['force']) && $params['force'] != true && strpos($params['content'], 'CREATE TABLE `' . rex::getTablePrefix() . 'article`') === false && strpos($params['content'], 'CREATE TABLE ' . rex::getTablePrefix() . 'article') === false) {
        return;
    }
    // check wheter tables exists
    $tables = rex_sql::showTables();
    if (!isset($tables[rex::getTablePrefix() . 'metainfo_field'])) {
        return false;
    }
    // since this extension may be used also when the addon is not yet installed,
    // require needed classes manually
    require_once __DIR__ . '/../lib/table_manager.php';
    $sql = rex_sql::factory();
    $sql->setQuery('SELECT name FROM ' . rex::getTablePrefix() . 'metainfo_field');
    for ($i = 0; $i < $sql->getRows(); ++$i) {
        if (substr($sql->getValue('name'), 0, 4) == 'med_') {
            $tableManager = new rex_metainfo_table_manager(rex::getTablePrefix() . 'media');
        } else {
            $tableManager = new rex_metainfo_table_manager(rex::getTablePrefix() . 'article');
        }
        $tableManager->deleteColumn($sql->getValue('name'));
        $sql->next();
    }
    // evtl reste aufräumen
    $tablePrefixes = ['article' => ['art_', 'cat_'], 'media' => ['med_']];
    foreach ($tablePrefixes as $table => $prefixes) {
        $table = rex::getTablePrefix() . $table;
        $tableManager = new rex_metainfo_table_manager($table);
        foreach (rex_sql::showColumns($table) as $column) {
            $column = $column['name'];
            if (in_array(substr($column, 0, 4), $prefixes)) {
                $tableManager->deleteColumn($column);
            }
        }
    }
    $sql = rex_sql::factory();
    $sql->setQuery('DELETE FROM ' . rex::getTablePrefix() . 'metainfo_field');
}
Esempio n. 2
0
function rex_metainfo_delete_field($fieldIdOrName)
{
    // Löschen anhand der FieldId
    if (is_int($fieldIdOrName)) {
        $fieldQry = 'SELECT * FROM ' . rex::getTablePrefix() . 'metainfo_field WHERE id=:idOrName LIMIT 2';
        $invalidField = rex_i18n::msg('minfo_field_error_invalid_fieldid');
    } elseif (is_string($fieldIdOrName)) {
        $fieldQry = 'SELECT * FROM ' . rex::getTablePrefix() . 'metainfo_field WHERE name=:idOrName LIMIT 2';
        $invalidField = rex_i18n::msg('minfo_field_error_invalid_name');
    } else {
        throw new InvalidArgumentException('MetaInfos: Unexpected type for $fieldIdOrName!');
    }
    // Feld existiert?
    $sql = rex_sql::factory();
    $sql->setQuery($fieldQry, [':idOrName' => $fieldIdOrName]);
    if ($sql->getRows() != 1) {
        return $invalidField;
    }
    $name = $sql->getValue('name');
    $field_id = $sql->getValue('id');
    $prefix = rex_metainfo_meta_prefix($name);
    $metaTable = rex_metainfo_meta_table($prefix);
    // Spalte existiert?
    $sql->setQuery('SELECT * FROM ' . $metaTable . ' LIMIT 1');
    if (!in_array($name, $sql->getFieldnames())) {
        return rex_i18n::msg('minfo_field_error_invalid_name');
    }
    $sql->setTable(rex::getTablePrefix() . 'metainfo_field');
    $sql->setWhere(['id' => $field_id]);
    $sql->delete();
    $tableManager = new rex_metainfo_table_manager($metaTable);
    return $tableManager->deleteColumn($name);
}