Author |
Topic  |
|
Jeepaholic
Average Member
  
USA
697 Posts |
Posted - 20 November 2003 : 19:39:12
|
NOTE: Many if the initial replies to this thread are due to an error I was having, it has been resolved, so you can ignore those posts...
UPDATE 11/22/03: Just noticed that all the unarchived posts appear as locked after the script runs, so I'll have to work on that a bit. Other'n that, things seem to work fine. FIXED: In order to have unarchived topics unlocked, view the code below and change one line (noted in red). This will make ALL unarchived topics unlocked, regardless of whether or not they were locked before archiving.
DESCRIPTION Much like the faster archiving script I created in THIS TOPIC, I've also created an un-archiving script that will unarchive all archived topics within a particular Forum.
Use Query Analyzer or Enterprise Manager to run this script. As always, BACKUP your DATABASE FIRST, and if possible, attempt this on a copy of the database before running it on your production systems. Use at your own risk!
I have implemented some error control within this to roll-back any changes if an error occurs, but nothing is always perfect. If for some reason you have duplicate TOPIC_ID's or REPLY_ID's within your normal *and* archived tables, or simply duplicates within your archive tables (I did) the script will fail and you will have to remove the incorrect entries. This happened to my database during one of my Snitz-based archives that timed out... Regardless, be careful when using something like this.
It should retain all of your original TOPIC_ID's, so previous links to these topics should not be affected in any way. Due to the error-handling and roll-back capabilities of this script, your forum will respond very slowly (or will time-out) until the Un-Archive is complete.
SCRIPT
DECLARE
@ArchiveForumID int,
@Error bit
SET
@ArchiveForumID = 3
SET
@Error = 0
BEGIN TRANSACTION UnArchive
SET IDENTITY_INSERT FORUM_TOPICS ON
INSERT INTO
FORUM_TOPICS
(
CAT_ID,
FORUM_ID,
TOPIC_ID,
T_STATUS,
T_MAIL,
T_SUBJECT,
T_MESSAGE,
T_AUTHOR,
T_REPLIES,
T_UREPLIES,
T_VIEW_COUNT,
T_LAST_POST,
T_DATE,
T_LAST_POSTER,
T_IP,
T_LAST_POST_AUTHOR,
T_LAST_POST_REPLY_ID,
T_ARCHIVE_FLAG,
T_LAST_EDIT,
T_LAST_EDITBY,
T_STICKY,
T_SIG,
T_EVENT_DATE,
T_ISEVENT
)
SELECT
CAT_ID,
FORUM_ID,
TOPIC_ID,
1,
T_MAIL,
T_SUBJECT,
T_MESSAGE,
T_AUTHOR,
T_REPLIES,
T_UREPLIES,
T_VIEW_COUNT,
T_LAST_POST,
T_DATE,
T_LAST_POSTER,
T_IP,
T_LAST_POST_AUTHOR,
T_LAST_POST_REPLY_ID,
T_ARCHIVE_FLAG,
T_LAST_EDIT,
T_LAST_EDITBY,
T_STICKY,
T_SIG,
T_EVENT_DATE,
T_ISEVENT
FROM
FORUM_A_TOPICS
WHERE
FORUM_ID = @ArchiveForumID
IF
@@Error <> 0
BEGIN
SET @Error = 1
PRINT 'UnArchive Failed at FORUM_TOPICS'
END
ELSE
BEGIN
PRINT 'UnArchive FORUM_TOPICS Completed'
END
SET IDENTITY_INSERT FORUM_TOPICS OFF
SET IDENTITY_INSERT FORUM_REPLY ON
INSERT INTO
FORUM_REPLY
(
CAT_ID,
FORUM_ID,
TOPIC_ID,
REPLY_ID,
R_MAIL,
R_AUTHOR,
R_MESSAGE,
R_DATE,
R_IP,
R_STATUS,
R_LAST_EDIT,
R_LAST_EDITBY,
R_SIG
)
SELECT
CAT_ID,
FORUM_ID,
TOPIC_ID,
REPLY_ID,
R_MAIL,
R_AUTHOR,
R_MESSAGE,
R_DATE,
R_IP,
R_STATUS,
R_LAST_EDIT,
R_LAST_EDITBY,
R_SIG
FROM
FORUM_A_REPLY
WHERE
FORUM_ID = @ArchiveForumID
IF
@@Error <> 0
BEGIN
SET @Error = 1
PRINT 'UnArchive Failed at FORUM_REPLY'
END
ELSE
BEGIN
PRINT 'UnArchive FORUM_REPLY Completed'
END
SET IDENTITY_INSERT FORUM_REPLY OFF
DELETE
FROM
FORUM_A_TOPICS
WHERE
FORUM_ID = @ArchiveForumID
PRINT 'Delete FORUM_A_TOPICS Completed'
DELETE
FROM
FORUM_A_REPLY
WHERE
FORUM_ID = @ArchiveForumID
PRINT 'Delete FORUM_A_REPLY Completed'
-- Update FORUM_TOTALS Counts
UPDATE
FORUM_TOTALS
SET
P_COUNT = (
SELECT
COUNT(*)
FROM
FORUM_REPLY
),
P_A_COUNT = (
SELECT
COUNT(*)
FROM
FORUM_A_REPLY
),
T_COUNT = (
SELECT
COUNT(*)
FROM
FORUM_TOPICS
),
T_A_COUNT = (
SELECT
COUNT(*)
FROM
FORUM_A_TOPICS
)
PRINT 'Update Counts for FORUM_TOTALS Completed'
-- Update Specific Forum Counts
UPDATE
FORUM_FORUM
SET
F_TOPICS = (
SELECT
COUNT(*)
FROM
FORUM_TOPICS
WHERE
FORUM_ID = @ArchiveForumID
),
F_COUNT = (
SELECT
COUNT(*)
FROM
FORUM_REPLY
WHERE
FORUM_ID = @ArchiveForumID
),
F_A_TOPICS = (
SELECT
COUNT(*)
FROM
FORUM_A_TOPICS
WHERE
FORUM_ID = @ArchiveForumID
),
F_A_COUNT = (
SELECT
COUNT(*)
FROM
FORUM_A_REPLY
WHERE
FORUM_ID = @ArchiveForumID
)
WHERE
FORUM_ID = @ArchiveForumID
PRINT 'Update Counts for Specific Forum Completed'
IF
@Error = 1
BEGIN
ROLLBACK TRANSACTION UnArchive
PRINT ''
PRINT 'UnArchive Failed, all Transactions Rolled Back to Original State'
END
ELSE
BEGIN
COMMIT TRANSACTION UnArchive
PRINT ''
PRINT 'Entire UnArchive Process Completed Successfully'
END
GO
|
Al Bsharah Aholics.com
Jeepaholics Anonymous Broncoholics Anonymous Network Insight
|
Edited by - Jeepaholic on 23 November 2003 01:52:59 |
|
ruirib
Snitz Forums Admin
    
Portugal
26364 Posts |
|
Jeepaholic
Average Member
  
USA
697 Posts |
Posted - 20 November 2003 : 20:51:29
|
I've run countless queries, and cannot find any matches... That's why I'm so frustrated! Here's a sample query:
select
fr.cat_id,
fr.forum_id,
fr.topic_id,
fr.reply_id,
fr.r_message,
far.cat_id,
far.forum_id,
far.topic_id,
far.reply_id,
far.r_message
from
forum_reply fr,
forum_a_reply far
where
fr.reply_id = far.reply_id
select
fr.cat_id,
fr.forum_id,
fr.topic_id,
-- fr.reply_id,
fr.t_subject,
far.cat_id,
far.forum_id,
far.topic_id,
-- far.reply_id,
far.t_subject
from
forum_topics fr,
forum_a_topics far
where
fr.topic_id = far.topic_id
|
Al Bsharah Aholics.com
Jeepaholics Anonymous Broncoholics Anonymous Network Insight
|
 |
|
ruirib
Snitz Forums Admin
    
Portugal
26364 Posts |
|
Jeepaholic
Average Member
  
USA
697 Posts |
Posted - 21 November 2003 : 01:56:50
|
Yeah, it's the four PK's: CAT_ID FORUM_ID TOPIC_ID REPLY_ID
I searched for a match on REPLY_ID, figuring that the PK requires all four to be identical to force an error...if one is a match, then I would check the other four manually to see if there was a match across all four. There are no matches. |
Al Bsharah Aholics.com
Jeepaholics Anonymous Broncoholics Anonymous Network Insight
|
 |
|
ruirib
Snitz Forums Admin
    
Portugal
26364 Posts |
Posted - 21 November 2003 : 04:41:36
|
Hmmm... did you check to see whether you have records with repeated REPLY_ID's in FORUM_A_REPLY? The table has no primary key, at least in its default definition, so that might be the issue. |
Snitz 3.4 Readme | Like the support? Support Snitz too |
 |
|
Jeepaholic
Average Member
  
USA
697 Posts |
Posted - 21 November 2003 : 12:14:41
|
UGH! No, I didn't...but that's a great (and probable) idea. Ugh...I knew I needed another set of eyes on this. Thanks, dude.
I just checked and I have 15,000 duplicates in my archive table. <sigh> Probably due to the Snitz archive script timing out. Time to clean house, I suppose.
Does the un-archive script look OK to you? I think it's right, can't find anything wrong with it...gonna work on cleaning up the DB and give the script some more testing... |
Al Bsharah Aholics.com
Jeepaholics Anonymous Broncoholics Anonymous Network Insight
|
 |
|
ruirib
Snitz Forums Admin
    
Portugal
26364 Posts |
|
Jeepaholic
Average Member
  
USA
697 Posts |
Posted - 22 November 2003 : 21:05:42
|
Ok. Finally got some good scripts to eliminate my duplicates and it appears the unarchive script is working. So, I'll release it as a BETA. Check the initial post for information! I unarchived over 200,000 posts in 4 forums in under 5 minutes. |
Al Bsharah Aholics.com
Jeepaholics Anonymous Broncoholics Anonymous Network Insight
|
Edited by - Jeepaholic on 22 November 2003 21:10:30 |
 |
|
sdetroch
Starting Member
9 Posts |
Posted - 10 June 2004 : 19:18:20
|
Hello,
I'm trying to unarchive my postings, but get the following error, can someone help?
Server: Msg 244, Level 16, State 2, Line 14 The conversion of the nvarchar value '20020907034344' overflowed an INT2 column. Use a larger integer column. The statement has been terminated. UnArchive Failed at FORUM_TOPICS
I think I should change some table properties? But which one? And to what?
Thx, Sven |
 |
|
Jeepaholic
Average Member
  
USA
697 Posts |
Posted - 10 June 2004 : 23:25:08
|
Hmmm... Are all of your DATE column types = nvarchar in all of your REPLY/TOPIC tables?
The string is definitely a date string, and all of the date strings (to my knowledge) are nvarchar's. So, there's no reason it should even be trying to put them into an integer field type.
Unless I'm missing something...? |
Al Bsharah Aholics.com
Jeepaholics Anonymous Broncoholics Anonymous Network Insight
|
 |
|
sdetroch
Starting Member
9 Posts |
Posted - 12 June 2004 : 05:47:12
|
Thanks for the info. I made all the A_TABLES and TABLES look exactly the same, but no help.
Anyway, in meantime I did an unarchive manually, it took about 15 minutes:
1) make REPLIES and A_REPLIES (and TOPICS and A_TOPICS) look exactly the same (same number of columns,...) on db level 2) export A_REPLIES and A_TOPICS to a flat file 3) import these textfiles in REPLIES and TOPICS 4) check forum postings 5) delete archive via (standard) mod counters will be updates as well
Sven |
 |
|
Jeepaholic
Average Member
  
USA
697 Posts |
Posted - 12 June 2004 : 21:21:40
|
I just realized that my EVENTS columns (ISEVENT and EVENTDATE) are shown in my script but aren't standard Snitz columns, it's possible you might not have had them in your table...or you had something else in place?
Glad you got it worked out, regardless... |
Al Bsharah Aholics.com
Jeepaholics Anonymous Broncoholics Anonymous Network Insight
|
 |
|
iperkins
Starting Member
USA
5 Posts |
Posted - 29 June 2004 : 14:55:30
|
I did not have those two column references, but the script worked beautifully when I took them out. Kudos! |
Ian M Perkins The guy that runs Fredweb |
 |
|
Jeepaholic
Average Member
  
USA
697 Posts |
|
|
Topic  |
|
|
|