You are here:  » Load global filter dump data with setup.sql?


Load global filter dump data with setup.sql?

Submitted by BobL on Wed, 2015-07-22 12:10 in

Hi David,
Hope all is well.

Was wondering if it's possible to load some global filters that we use in each sub install into the setup.sql file.
That way they are there when we run setup for the installs?

I'm getting olde you know, and have that sometimers...

Thanks in advance.
Bob L.

Submitted by support on Wed, 2015-07-22 13:28

Hello Bob,

Sure - first of all, set-up an installation with Global Filters configured as you wish to apply to all new installations. Then create a new script filterssql.php as follows:

<?php
  
require("includes/common.php");
  
header("Content-Type: text/plain");
  
$sql "SELECT field,name,created,HEX(data) AS data FROM `".$config_databaseTablePrefix."filters` WHERE filename=''";
  
database_querySelect($sql,$filters);
  foreach(
$filters as $filter)
  {
    
$sql "INSERT INTO filters SET
      field='"
.database_safe($filter["field"])."',
      name='"
.database_safe($filter["name"])."',
      created='"
.database_safe($filter["created"])."',
      data=UNHEX('"
.$filter["data"]."');
    "
;
    
$sql str_replace(array("\n","\r")," ",$sql)."\n";
    
$sql preg_replace('/[ ]{2,}/',' ',$sql);
    print 
$sql;
  }
?>

Browse to the script from the top level of your Price Tapestry installation and this will dump the INSERT INTO queries for the global filters that you can add to the end of setup.sql.

Note that the table name in the generated INSERT query does not include the database table prefix. This is because setup.php inserts this when the setup process is run, however the script is only expecting CREATE TABLE queries so a small modification is required to support INSERT INTO queries also. To do this, edit setup.php and look for the following code at line 31:

  $data = str_replace("CREATE TABLE ","CREATE TABLE ".$config_databaseTablePrefix,$data);

...and REPLACE with:

  $data = str_replace("CREATE TABLE ","CREATE TABLE ".$config_databaseTablePrefix,$data);
  $data = str_replace("INSERT INTO ","INSERT INTO ".$config_databaseTablePrefix,$data);

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by BobL on Wed, 2015-07-22 13:41

Bob L.

Wow, you are really great at support David.

Thank you.
Was wondering how to do this without logging into MyPhpAdmin every time and run an sql query or create them in admin when I remember.

Bob L.