You are here:  » Import an additional single file to pt_import table


Import an additional single file to pt_import table

Submitted by CashNexus on Sat, 2022-05-28 06:51 in

Hello David,
let me also ask - is it possible to import a single datafeed file not to PT_PRODUCTS table
/usr/bin/php -q /scripts/import.php file.xml
but to PT_IMPORT table ?

I've created a copy of /scripts/import.php as /scripts/import_to_pt_import.php
but I don't see a possibility inside a code there to change destination table to PT_IMPORT for a single file instead of default PT_PRODUCTS.
PT_IMPORT there is only for @ALL.

Thank you in advance for a hint !
Best regards
Serge

Submitted by support on Mon, 2022-05-30 08:50

Hello Serge,

The pt_products_import table is only intended to be transient; it's how the "zero down time" import method works by creating a temporary table pt_products_import, importing all feeds to that table and then subsequently dropping the original table and renaming pt_products_import to pt_products.

If you wanted to do something similar, e.g. import a single feed into the table pt_products_temp (and not DROP the table after the import) then in your copy of import.php look for the following code beginning at line 109:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."feeds` WHERE filename='".database_safe($filename)."'";
    if (database_querySelect($sql,$rows))
    {
      $feed = $rows[0];
      import();
    }

...and REPLACE with:

    $admin_importTemp = TRUE;
    $sql = "DROP TABLE IF EXISTS `".$config_databaseTablePrefix."products_temp`";
    database_queryModify($sql,$result);
    $sql = "CREATE TABLE `".$config_databaseTablePrefix."products_temp` LIKE `".$config_databaseTablePrefix."products`";
    database_queryModify($sql,$result);
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."feeds` WHERE filename='".database_safe($filename)."'";
    if (database_querySelect($sql,$rows))
    {
      $feed = $rows[0];
      import();
    }

And then in includes/admin.php look for the following code at line 494:

    if (isset($admin_importAll))

...and REPLACE with:

    global $admin_importTemp;
    if (isset($admin_importTemp))
    {
      $table = "products_temp";
    }
    elseif (isset($admin_importAll))

And finally the following code at line 717:

    if (isset($admin_importAll))

...and REPLACE with:

    global $admin_importTemp;
    if (isset($admin_importTemp))
    {
      $table = "products_temp";
    }
    elseif (isset($admin_importAll))

Cheers,
David.
--
PriceTapestry.com

Submitted by CashNexus on Mon, 2022-05-30 17:48

Hello David,
glad to have your answer, thank you !
But could you, please, have a look to your code again.

I assure I did exactly as you have instructed, no errors, pt_products_temp has created
- but anyway when I make an import of single file using
cd /scripts/ ; /usr/bin/php -q import_tmp.php MyData.xml
it imports to main pt_products table but not to pt_products_temp.
pt_products_temp table remains empty,
Regards,
Serge

Submitted by CashNexus on Mon, 2022-05-30 18:56

A little later :)
Dear David,
let me explain a little to simplify my question.
We don't need a products_temp table because during total update I first use usual
/scripts/import.php where I commented replace pt_import to pt_products
then I make some additional processing of pt_import table (my own needs, word count or example)
and then I use simple script
/scripts/replace_tmp_import.php
what quickly performs remove of old pt_products and rename of pt_import to pt_products.

So I just need an additional function what allows import of a single file exactly to pt_import table
/usr/bin/php -q /scripts/import.php file.xml

Thank you again for your attention !
Best regards
Serge

Submitted by support on Tue, 2022-05-31 11:40

Hello Serge,

You mentioned using distribution 01/06, which in includes/admin.php has the following code in the import record handler function at line 260:

    $sql = sprintf("INSERT INTO `".$config_databaseTablePrefix."products` SET

Did you modify this in the version you are running?

Correspondingly, in scripts/import.php is the table name different for the TRUNCATE at line 55:

  $sql = "TRUNCATE `".$config_databaseTablePrefix."products`";

(only applies when importing @ALL)

...and has the following code beginning at line 89 (when importing individual feed)

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."feeds` WHERE filename='".database_safe($filename)."'";
    if (database_querySelect($sql,$rows))
    {
      $feed = $rows[0];
      import();
    }

Cheers,
David.
--
PriceTapestry.com

Submitted by CashNexus on Tue, 2022-05-31 15:21

Hello David,
so many years with your PT script :)) so I've got your logic and found that it seems you made an error in your first answer :)
{code saved}

When I've corrected as above - everything works as expected !
So thank you very much for the right hint !
Take care !
Best regards
Serge

Submitted by support on Tue, 2022-05-31 18:53

Corrected above!

Cheers,
David.
--
PriceTapestry.com