Important announcements from CouchCMS team
18 posts Page 2 of 2
A little update to get file uploaded from the front-end (securefile).
viewtopic.php?f=2&t=10417
Hi all,
we have now succeded in importing the .csv file. Now I wander how the updating process is working.
How can we update the database with a new updated csv file? If I import a new csv file with the same products (same product names and same fields), but updated, I get duplicate products.
Any idea?
Thanks
@Danno,
How can we update the database with a new updated csv file? If I import a new csv file with the same products (same product names and same fields), but updated, I get duplicate products
.
To prevent duplicate pages from being created, before actually creating a page we'll need to first check if the page does not already exist. The 'page_name' of a page is its unique ID so we can use it to do the check.

To help you, following is some example code. I'm continuing to use the 'cars.php' example used in the original post.
Code: Select all
<!-- database operation here -->

    <!-- set the following two variables to match your use-case -->
    <cms:set my_template_name = 'cars.php' />
    <cms:set my_page_title = "<cms:show _car_make/> <cms:show _car_model/>" />

    <!-- 1. convert the title into unique page_name -->
    <cms:php>
        global $CTX, $FUNCS;
        $name = $FUNCS->get_clean_url( "<cms:show my_page_title />" );
        $CTX->set( 'my_page_name', $name );
    </cms:php>

    <!-- 2. try to find a page by the name generated above -->
    <cms:set my_page_id = '' 'global' />
    <cms:pages masterpage=my_template_name page_name=my_page_name limit='1' show_future_entries='1'>
        <cms:set my_page_id=k_page_id  'global' />
    </cms:pages>

    <!-- 3. if 'my_page_id' is empty at this point, the page does not exist - so safe to create one now -->
    <cms:if my_page_id=''>

        <!-- CREATE HERE -->
        <cms:db_persist>
            ..
            ..
        </cms:db_persist>
    </cms:if>

Some notes on the code above -
It is meant to be added to the original code (just below the "<!-- database operation here -->" line there).
As I mentioned, we need the 'page_name' to search for duplicates. In the original code, we only have the 'page_title' (a combination of "<cms:show _car_make/> <cms:show _car_model/>") so the code above uses a tittle PHP to convert the 'title' to a unique 'name'.

Then we use <cms:pages> with the name to search for the page. If the page is *not* found, we continue with the original logic and use <cms:db_persist> to create a new page.

IMP:
To adapt the code above to your use case, please modify the top two lines and place values matching that of your use-case -
<!-- set the following two variables to match your use-case -->
<cms:set my_template_name = 'cars.php' />
<cms:set my_page_title = "<cms:show _car_make/> <cms:show _car_model/>" />

Hope it helps.
I'm sorry, I'm not really great with this. All the explanations are actually making it more difficult for me :?

Can I just get a straight up code example for how to bulk import cloned pages from the admin panel? To clarify, I need this as an option where the user uploads the import file (not a one-off import).

Thanks!
@BlueCaret, I concede this addon is a little advanced.
However, this is all that we have at the moment, I am afraid.

If you feel you won't be able to tailor it to suit your use-case, you may hire somebody to do that for you.
It is possible to produce data type relationships using this module?
Thanks :)
Jiwa wrote: It is possible to produce data type relationships using this module?
Thanks :)

Yes, db_persist tag supports it perfectly. It is written as relation_editable_name = related_page_id, for example, city = 121.
Thank you, Trendoman! It really helped :)
18 posts Page 2 of 2

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 2 guests