function rex_copyRevisionContent($article_id, $clang, $from_revision_id, $to_revision_id, $from_re_sliceid = 0, $to_revision_delete = FALSE) { global $REX; if ($to_revision_delete) { $dc = new rex_sql(); // $dc->debugsql = 1; $dc->setQuery('delete from ' . $REX['TABLE_PREFIX'] . 'article_slice where article_id=' . $article_id . ' and clang=' . $clang . ' and revision=' . $to_revision_id); } if ($from_revision_id == $to_revision_id) { return false; } $gc = new rex_sql(); // $gc->debugsql = 1; $gc->setQuery("select * from " . $REX['TABLE_PREFIX'] . "article_slice where re_article_slice_id='{$from_re_sliceid}' and article_id='{$article_id}' and clang='{$clang}' and revision='{$from_revision_id}'"); if ($gc->getRows() == 1) { // letzt slice_id des ziels holen .. $glid = new rex_sql(); // $glid->debugsql = 1; $glid->setQuery("\n\t\t\t\t\tselect \n\t\t\t\t\t\tr1.id, r1.re_article_slice_id\n\t from \n\t\t\t\t\t\t" . $REX['TABLE_PREFIX'] . "article_slice as r1\n\t\t\t\t\tleft join " . $REX['TABLE_PREFIX'] . "article_slice as r2 on r1.id = r2.re_article_slice_id\n\t where \n\t\t\t\t\t\tr1.article_id = {$article_id} and r1.clang = {$clang} and \n\t\t\t\t\t\tr2.id is NULL and \n\t\t\t\t\t\tr1.revision='{$to_revision_id}';"); if ($glid->getRows() == 1) { $to_last_slice_id = $glid->getValue("r1.id"); } else { $to_last_slice_id = 0; } $ins = new rex_sql(); // $ins->debugsql = 1; $ins->setTable($REX['TABLE_PREFIX'] . "article_slice"); $cols = new rex_sql(); $cols->setquery("SHOW COLUMNS FROM " . $REX['TABLE_PREFIX'] . "article_slice"); for ($j = 0; $j < $cols->rows; $j++, $cols->next()) { $colname = $cols->getValue("Field"); if ($colname == "re_article_slice_id") { $value = $to_last_slice_id; } elseif ($colname == "revision") { $value = $to_revision_id; } elseif ($colname == "createdate") { $value = time(); } elseif ($colname == "updatedate") { $value = time(); } elseif ($colname == "createuser") { $value = $REX["USER"]->getValue("login"); } elseif ($colname == "updateuser") { $value = $REX["USER"]->getValue("login"); } else { $value = $gc->getValue($colname); } if ($colname != "id") { $ins->setValue($colname, $ins->escape($value)); } } $ins->insert(); // id holen und als re setzen und weitermachen.. rex_copyRevisionContent($article_id, $clang, $from_revision_id, $to_revision_id, $gc->getValue("id")); return true; } rex_generateArticle($article_id); return true; }
/** * Kopiert die Inhalte eines Artikels in einen anderen Artikel * * @param $from_id ArtikelId des Artikels, aus dem kopiert werden (Quell ArtikelId) * @param $to_id ArtikelId des Artikel, in den kopiert werden sollen (Ziel ArtikelId) * @param [$from_clang] ClangId des Artikels, aus dem kopiert werden soll (Quell ClangId) * @param [$to_clang] ClangId des Artikels, in den kopiert werden soll (Ziel ClangId) * @param [$from_re_sliceid] Id des Slices, bei dem begonnen werden soll */ function rex_copyContent($from_id, $to_id, $from_clang = 0, $to_clang = 0, $from_re_sliceid = 0) { global $REX, $REX_USER; if ($from_id == $to_id && $from_clang == $to_clang) { return false; } $gc = new rex_sql(); $gc->setQuery("select * from " . $REX['TABLE_PREFIX'] . "article_slice where re_article_slice_id='{$from_re_sliceid}' and article_id='{$from_id}' and clang='{$from_clang}'"); if ($gc->getRows() == 1) { // letzt slice_id des ziels holen .. $glid = new rex_sql(); $glid->setQuery("select r1.id, r1.re_article_slice_id\n from " . $REX['TABLE_PREFIX'] . "article_slice as r1\n left join " . $REX['TABLE_PREFIX'] . "article_slice as r2 on r1.id=r2.re_article_slice_id\n where r1.article_id={$to_id} and r1.clang={$to_clang} and r2.id is NULL;"); if ($glid->getRows() == 1) { $to_last_slice_id = $glid->getValue("r1.id"); } else { $to_last_slice_id = 0; } $ins = new rex_sql(); // $ins->debugsql = 1; $ins->setTable($REX['TABLE_PREFIX'] . "article_slice"); $cols = new rex_sql(); // $cols->debugsql = 1; $cols->setquery("SHOW COLUMNS FROM " . $REX['TABLE_PREFIX'] . "article_slice"); for ($j = 0; $j < $cols->rows; $j++, $cols->next()) { $colname = $cols->getvalue("Field"); if ($colname == "clang") { $value = $to_clang; } elseif ($colname == "re_article_slice_id") { $value = $to_last_slice_id; } elseif ($colname == "article_id") { $value = $to_id; } elseif ($colname == "createdate") { $value = time(); } elseif ($colname == "updatedate") { $value = time(); } elseif ($colname == "createuser") { $value = $REX_USER->getValue("login"); } elseif ($colname == "updateuser") { $value = $REX_USER->getValue("login"); } else { $value = addslashes($gc->getValue("{$colname}")); } if ($colname != "id") { $ins->setValue($colname, $value); } } $ins->insert(); // id holen und als re setzen und weitermachen.. rex_copyContent($from_id, $to_id, $from_clang, $to_clang, $gc->getValue("id")); return true; } rex_generateArticle($to_id); return true; }
/** * Erstellt einen SQL Dump, der die aktuellen Datebankstruktur darstellt * @return string SQL Dump der Datenbank */ function rex_a1_export_db() { global $REX; $tabs = new rex_sql(); $tabs->setquery('SHOW TABLES'); $dump = ''; // ----- EXTENSION POINT rex_register_extension_point('A1_BEFORE_DB_EXPORT'); for ($i = 0; $i < $tabs->rows; $i++, $tabs->next()) { $tab = $tabs->getValue('Tables_in_' . $REX['DB']['1']['NAME']); if (strstr($tab, $REX['TABLE_PREFIX']) == $tab && $tab != $REX['TABLE_PREFIX'] . 'user' && substr($tab, 0, strlen($REX['TABLE_PREFIX'] . $REX['TEMP_PREFIX'])) != $REX['TABLE_PREFIX'] . $REX['TEMP_PREFIX']) { $cols = new rex_sql(); $cols->setquery("SHOW COLUMNS FROM `" . $tab . "`"); $query = "DROP TABLE IF EXISTS `" . $tab . "`;\nCREATE TABLE `" . $tab . "` ("; // Spalten auswerten for ($j = 0; $j < $cols->rows; $j++) { $colname = $cols->getValue('Field'); $coltype = $cols->getValue('Type'); // Null Werte if ($cols->getValue('Null') == 'YES') { $colnull = 'NULL'; } else { $colnull = 'NOT NULL'; } // Default Werte if ($cols->getValue('Default') != '') { $coldef = 'DEFAULT \'' . str_replace("'", "\\'", $cols->getValue('Default')) . '\''; } else { $coldef = ''; } // Spezial Werte $colextra = $cols->getValue('Extra'); $query .= " `{$colname}` {$coltype} {$colnull} {$coldef} {$colextra}"; if ($j + 1 != $cols->rows) { $query .= ","; } $cols->next(); } // Indizes Auswerten $indizes = new rex_sql(); $indizes->setQuery('SHOW INDEX FROM `' . $tab . '`'); $primary = array(); $uniques = array(); $fulltexts = array(); for ($x = 0; $x < $indizes->getRows(); $x++) { if ($indizes->getValue('Index_type') == 'BTREE') { if ($indizes->getValue('Key_name') != 'PRIMARY') { $uniques[$indizes->getValue('Key_name')][] = $indizes->getValue('Column_name'); } else { $primary[$indizes->getValue('Key_name')][] = $indizes->getValue('Column_name'); } } else { if ($indizes->getValue('Index_type') == 'FULLTEXT') { $fulltexts[$indizes->getValue('Key_name')][] = $indizes->getValue('Column_name'); } } $indizes->next(); } // Primary key Auswerten foreach ($primary as $name => $columnNames) { // , UNIQUE KEY `name` (`spalten`,..) $query .= ", PRIMARY KEY (`" . implode('`,`', $columnNames) . "`)"; } // Unique Index Auswerten foreach ($uniques as $name => $columnNames) { // , UNIQUE KEY `name` (`spalten`,..) $query .= ", UNIQUE KEY `" . $name . "`(`" . implode('`,`', $columnNames) . "`)"; } // Unique Index Auswerten foreach ($fulltexts as $name => $columnNames) { // , FULLTEXT KEY `name` (`spalten`,..) $query .= ", FULLTEXT KEY `" . $name . "`(`" . implode('`,`', $columnNames) . "`)"; } $query .= ") TYPE=MyISAM;"; $dump .= $query . "\n"; // Inhalte der Tabelle Auswerten $cont = new rex_sql(); $cont->setquery("SELECT * FROM `" . $tab . "`"); for ($j = 0; $j < $cont->rows; $j++, $cont->next()) { $query = "INSERT INTO `" . $tab . "` VALUES ("; $cols->counter = 0; for ($k = 0; $k < $cols->rows; $k++, $cols->next()) { $con = $cont->getValue($cols->getValue("Field")); if (is_numeric($con)) { $query .= "'" . $con . "'"; } else { $query .= "'" . addslashes($con) . "'"; } if ($k + 1 != $cols->rows) { $query .= ","; } } $query .= ");"; $dump .= str_replace(array("\r\n", "\n"), '\\r\\n', $query) . "\n"; } } } // Versionsstempel hinzufügen $dump = str_replace("\r", "", $dump); $header = "## Redaxo Database Dump Version " . $REX['VERSION'] . "\n"; $header .= "## Prefix " . $REX['TABLE_PREFIX'] . "\n"; $content = $header . $dump; // ----- EXTENSION POINT $content = rex_register_extension_point('A1_AFTER_DB_EXPORT', $content); return $content; }