Copy Wiki to another project
Added by Sebastián Brant over 14 years ago
I need to copy/updete a wiki from one proyect, let say "project 1", to another, "project 2".
There are a command or a sentence (Store procedure or something) for this?
Thanks!
Replies (5)
RE: Copy Wiki to another project - Added by Felix Schäfer over 14 years ago
You can copy a whole project and selectively choose which parts/modules you want to copy, but I don't know of any procedure to copy it into an existing project. Depending on your rails-foo, you might be able to localize the method that copies only the wiki, but I'd advise against it.
RE: Copy Wiki to another project - Added by Felipe Rodriguez over 14 years ago
I need to copy wikis too,
Can it help me to build a procedure copying and modifing records in the database?
I try to do that but RedMine crashes until now.
Im working on wiki_pages and wiki_content tables by now.
there will somthing else to change?
RE: Copy Wiki to another project - Added by Felix Schäfer over 14 years ago
I would strongly suggest against working with the DB directly as rails is an ORM that wraps the DB data into models for the rails app.
RE: Copy Wiki to another project - Added by Felipe Rodriguez over 14 years ago
against your suggest and because im not familiarized with Ruby i created this Procedure:
@
DELIMITER //
DROP PROCEDURE IF EXISTS replicawiki2;
CREATE PROCEDURE replicawiki2(wikid_from INT, wikid_to INT)
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE last_id INT;
DECLARE st_page VARCHAR;
DECLARE curso INT;
DECLARE id_or INT;
DECLARE id_nu INT;
DECLARE pages CURSOR FOR SELECT id FROM wiki_pages wp WHERE wp.wiki_id = wikid_from;
DECLARE copied_pages CURSOR FOR SELECT id_original, id_new FROM aux_map;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
- CAUTION THIS ERASE ALL CURRENT WIKI PAGES of DESTINATION (TO) WIKI
DELETE FROM wiki_pages WHERE wiki_pages.wiki_id = wikid_to ;
OPEN pages;
#Fix wikis start page
SELECT wikis.start_page INTO st_page FROM wikis WHERE id = wikid_from;
UPDATE wikis SET start_page = st_page WHERE id = wikid_to;
- aux table to replicate the hierachy
DROP TABLE IF EXISTS aux_map;
CREATE TABLE aux_map(id_original INT, id_new INT);
#copy redirects
INSERT INTO wiki_redirects (wiki_id, `title`, redirects_to, created_on)
SELECT wikid_to as wiki_id, `title`, redirects_to, created_on FROM wiki_redirects WHERE wiki_id = wikid_from;
#copy all the wiki pages to origin to dest. and fill the auxiliary hierachy table
REPEAT
FETCH pages INTO curso;
INSERT INTO wiki_pages (wiki_id, title, created_on, protected, parent_id)
SELECT wikid_to as wiki_id, wp.title, wp.created_on, wp.protected, wp.parent_id FROM wiki_pages wp WHERE wp.id = curso limit 1;
SET last_id = last_insert_id();
INSERT INTO aux_map (id_original, id_new)
VALUES(curso, last_id);
UNTIL done END REPEAT;
SET done = 0;
OPEN copied_pages;
#update hierachy and copy all the wiki contents.
REPEAT
FETCH copied_pages INTO id_or, id_nu;
UPDATE wiki_pages SET parent_id = id_nu WHERE wiki_id = wikid_to AND parent_id = id_or;
INSERT INTO wiki_contents (page_id, author_id, `text`, `comments`, `updated_on`, `version`)
SELECT id_nu as page_id, author_id, `text`, `comments`, `updated_on`, `version` FROM wiki_contents wc WHERE wc.page_id = id_or;
UNTIL done END REPEAT;
CLOSE pages;
CLOSE copied_pages;
#Deleting auxiliary table
DROP TABLE IF EXISTS aux_map;
END
//
@
RE: Copy Wiki to another project - Added by Felipe Rodriguez over 14 years ago
Sorry i dont take the preview before ...
I atach the .sql.
replicawiki2.sql (2.22 KB) replicawiki2.sql | Copy wiki to existing project |