WBCE CMS Forum

WBCE CMS – Way Better Content Editing.

You are not logged in.

#1 23.01.2023 22:21:26

losttrip
Member

Import old News Posts to NWI

I am migrating a WB 2.10 site to WBCE 1.5.4.  Actually I am recreating the site from scratch in WBCE 1.5.4.

I knew it would be tedious, but worth the effort, in my opinion.  But I have hit a serious bottleneck.  The old site has hundreds of News posts.  I started to add each post on the new site, but it's taking much longer than I imagined.

I looked at the databases for the two sites (old) "mod_news_posts" and (new) "mod_news_img_posts", and I am pretty confident I could export the old database, and edit it in a text editor to work in the new database.  Although I don't have a lot of experience with this.

old News Database

new NWI database

But I have a feeling that's not all there is to it.  For instance, I see php files for each post under "pages/posts"
e.g.,

[== PHP ==]
<?php
$page_id = 2;
$section_id = 3;
$post_id = 4;

define("POST_SECTION", $section_id);
define("POST_ID", $post_id);
require("../../config.php");
require(WB_PATH."/index.php");
?>

Would I need to manually create each of these files as well?

Is there anything else I need to check or look out for?

Thank you for your time.

Online

#2 23.01.2023 22:33:19

florian
Administrator

Re: Import old News Posts to NWI

NWI has an import tool for news posts. So you can try the following:
1) Create a database dump from the old news_posts table
2) Install the old news module on the new WBCE  page (https://addons.wbce.org/pages/addons.php?do=item&item=7)
3) Open the dump of the old News_img table with an editor like Notepad++ and change the first two values after the opening bracket according to the page id / section id of the old news module in your new site
4) import the changed sql file into the database of your new WBCE site (change prefix of table to import if necessary)
5) Check (in the backend)  if the news posts appear on the news page
6) Create a new, empty NWI page
7) There sholud appear an "import from" select box, choose the news section you just filled
8) If the import was successful, delete the news page from which you imported the posts
9) Uninstall the news module

Last edited by florian (24.01.2023 06:31:30)

Offline

#3 24.01.2023 04:02:35

losttrip
Member

Re: Import old News Posts to NWI

Thank you.  I will try this.

I did do a few forum searches (English) but wasn't successful in finding this information.

Online

#4 25.01.2023 23:03:08

losttrip
Member

Re: Import old News Posts to NWI

Hi Florian.  Using your instructions, I was able to import all of the old News posts to NWI.  The posts all appear in the backend and the frontend.

But when you click "read more" on any post, you go to a white page.  I checked the file system and no php files exist for any of the post under "pages/posts".  I opened one of the NWI posts in the backend and saved it and the php file was created for that post.  Is a re-save of EVERY post necessary to complete this migration?

Online

#5 Yesterday 08:28:18

florian
Administrator

Re: Import old News Posts to NWI

Hm, that ist strange. Actually the access files should have been recreated on import and no further action should be necessary.

Anyway, I've created (copied&pasted) a quick&dirty script to create all accessfiles of a given section.

1) Add a code2 section to the NWI page with the missing access files.
2.) Paste the following code into it:

global $database;
$posts = array();
$nwisection = 39;

$query = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_news_img_posts` WHERE `section_id`=".$nwisection);
    if ($query->numRows() > 0) {
        while ($post = $query->fetchRow()) {
            $posts[] = $post;
        }
    }

include_once WB_PATH.'/modules/news_img/functions.inc.php';

for ($i=0; $i<sizeof($posts); $i++) {
 

$old_link = $posts[$i]['link'];

// potential new link
$post_link = '/posts/'.page_filename($posts[$i]['title']);
// make sure to have the post_id as suffix; this will make the link unique (hopefully...)
if (substr_compare($post_link, $posts[$i]['post_id'], -(strlen($posts[$i]['post_id'])), strlen($posts[$i]['post_id']))!=0) {
    $post_link .= PAGE_SPACER.$posts[$i]['post_id'];
}

// Make sure the post link is set and exists
// Make news post access files dir
make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/');
$file_create_time = '';
if (!is_writable(WB_PATH.PAGES_DIRECTORY.'/posts/')) {
    $admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
} else {
    // We need to create a new file
    // First, delete old file if it exists
    if (file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION)) {
        $file_create_time = filemtime(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION);
        unlink(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION);
    }
    if ($page_id != $old_page_id or $section_id != $old_section_id) {
        $file_create_time = '';
    }
    // Specify the filename
    $filename = WB_PATH.PAGES_DIRECTORY.'/'.$post_link.PAGE_EXTENSION;
    mod_nwi_create_file($filename, $file_create_time, $posts[$i]['post_id'],$nwisection,$page_id);
    echo "created ".$posts[$i]['link'].'<br>';
}
  
}

3.) Change the value for $nwisection according to the actual nwi section.
attachment.php?item=3335&download=1

4.) Click on the "save" button of the code2 section.
5.) Call the frontend view of the page. Below the news items a list like "created /posts/some-text-here1" and so on appears.
6.) Check some news posts in the frontend.
7.) Remove the code 2 section.

To make sure that really all access files exist, install the System information tool from AOR. On the "pages" tab, below the regular pages, you can check if all NWI access files exist and create missing ones if necessary.

Last edited by florian (Yesterday 08:31:56)

Offline

#6 Yesterday 23:09:33

losttrip
Member

Re: Import old News Posts to NWI

florian wrote:

Hm, that ist strange. Actually the access files should have been recreated on import and no further action should be necessary.

I will definitely give your script a try.  Thank you for going to that trouble.

But, I would be interested in determining what went wrong to cause the access files to not be created on import.  Just in case I did something wrong, or missed something... and so that I understand the process for future reference.

Is it possible that the access files were not "recreated" because there were no access files for the original posts that were imported from the News module page?  There were no access files for those News posts because I did a database table import of the edited sql file.

Or does the NWI "import" function not look at the original News page access files in order to create the new NWI access files on import?

Online

#7 Today 01:08:24

florian
Administrator

Re: Import old News Posts to NWI

I don't know what went wrong. The NWI import tool should create the access files on import in any case, wether they exist or not, since they contain other values than the original files. Also the /posts directory should be created if does not exist and if the directory isn't writeable, there should appear an error message.
You can check if there are any corresponding entries in the error log which might explain the missing access files.
Also I'm interested if the script worked.

Offline

Board footer

up