Exemple #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) {
        $prefix = rex_metainfo_meta_prefix($sql->getValue('name'));
        $table = rex_metainfo_meta_table($prefix);
        $tableManager = new rex_metainfo_table_manager($table);
        $tableManager->deleteColumn($sql->getValue('name'));
        $sql->next();
    }
    // evtl reste aufräumen
    $tablePrefixes = ['article' => ['art_', 'cat_'], 'media' => ['med_'], 'clang' => ['clang_']];
    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');
}
Exemple #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);
}
Exemple #3
0
<?php

/**
 * MetaForm Addon.
 *
 * @author markus[dot]staab[at]redaxo[dot]de Markus Staab
 *
 * @package redaxo5
 */
// Parameter
$Basedir = __DIR__;
$subpage = rex_be_controller::getCurrentPagePart(2);
$func = rex_request('func', 'string');
echo rex_view::title(rex_i18n::msg('minfo_title'));
// Include Current Page
switch ($subpage) {
    case 'media':
        $prefix = 'med_';
        break;
    case 'categories':
        $prefix = 'cat_';
        break;
    default:
        $prefix = 'art_';
}
$metaTable = rex_metainfo_meta_table($prefix);
require $Basedir . '/field.php';