VbzCart/docs/pieces/catalog/building/2009: Difference between revisions

From Woozle Writes Code
< VbzCart‎ | docs‎ | pieces‎ | catalog‎ | building
Jump to navigation Jump to search
imported>Woozle
(updated name of source query in STAGE 2; added about/history)
imported>Woozle
(line numbering; line formatting)
Line 1: Line 1:
==About==
==About==
* '''History''':
* '''History''':
** '''2009-12-10''' Transcribed from development source; updated name of source query in STAGE 2
** '''2009-12-10''' Transcribed from development source; updated name of source query in STAGE 2; added statement numbers for debugging purposes and changed line formatting for better readability
==PHP code==
==PHP code==
This defines the array which stores the SQL commands to be executed, in order. The key to each array element is the description to be shown to the administrator when executing that command.
This defines the array which stores the SQL commands to be executed, in order. The key to each array element is the description to be shown to the administrator when executing that command.
<php>$arSQL_CtgBuild = array(
<php>$arSQL_CtgBuild = array(
/* STAGE 1: Clear/refill the two temporary tables from which cat_items is updated. */
/* STAGE 1: Clear/refill the two temporary tables from which cat_items is updated. */
   'clear update table 1 of 2' => 'DELETE FROM ctg_upd1;',
   '1.1 clear update table 1 of 2' => 'DELETE FROM ctg_upd1;',
   'clear update table 2 of 2' => 'DELETE FROM ctg_upd2;',
   '1.2 clear update table 2 of 2' => 'DELETE FROM ctg_upd2;',
   /* == Fill temp tables == */
   /* == Fill temp tables == */
     /* -- generated source data: */
     /* -- generated source data: */
   'fill update table 1/2 with source data' => 'INSERT INTO ctg_upd1 SELECT
   '1.3 fill update table 1/2 with source data'
    CatSfx, isCloseOut, ID_CTG_Title, ID_CTG_Item, ID_Title, ID_ItTyp, ID_ItOpt, ID_ShipCost, PriceBuy, PriceSell, PriceList,
  => 'INSERT INTO ctg_upd1 SELECT
    ItOpt_Descr_part, NameSng, GrpItmDescr, TitleGroupDescr, OptionDescr, ItOpt_Sort,
CatSfx, isCloseOut, ID_CTG_Title, ID_CTG_Item, ID_Title, ID_ItTyp, ID_ItOpt, ID_ShipCost, PriceBuy, PriceSell, PriceList,
    GrpCode, GrpDescr, GrpSort, IDS_Item, CatNum, ItOpt_Descr  
ItOpt_Descr_part, NameSng, GrpItmDescr, TitleGroupDescr, OptionDescr, ItOpt_Sort,
  FROM qryCtg_src;',
GrpCode, GrpDescr, GrpSort, IDS_Item, CatNum, ItOpt_Descr  
      FROM qryCtg_src;',
     /* -- existing catalog data indexed for JOINing: */
     /* -- existing catalog data indexed for JOINing: */
   'fill update table 2/2 with pre-join data' => 'INSERT INTO ctg_upd2 SELECT *, 0 AS cntDups
   '1.4 fill update table 2/2 with pre-join data'
  FROM qryCtg_Items_forUpdJoin
    => 'INSERT INTO ctg_upd2 SELECT *, 0 AS cntDups
  ON DUPLICATE KEY UPDATE cntDups=cntDups+1;',
      FROM qryCtg_Items_forUpdJoin
      ON DUPLICATE KEY UPDATE cntDups=cntDups+1;',
/* STAGE 2: Calculate stock numbers and set isForSale flag */
/* STAGE 2: Calculate stock numbers and set isForSale flag */
   /* -- calculate stock quantities; set for-sale flag if in stock */
   /* -- calculate stock quantities; set for-sale flag if in stock */
   'calculate stock quantities and status' => 'UPDATE ctg_upd2 AS i LEFT JOIN qryStk_items_remaining AS s ON i.ID_Item=s.ID_Item
   '2.1 calculate stock quantities and status'
  SET
    => 'UPDATE ctg_upd2 AS i LEFT JOIN qryStk_items_remaining AS s ON i.ID_Item=s.ID_Item
    i.qtyInStock=s.QtyForSale,
      SET
    i.isForSale=(s.QtyForSale > 0);',
i.qtyInStock=s.QtyForSale,
i.isForSale=(s.QtyForSale > 0);',
   /* -- also set for-sale flag if available from source */
   /* -- also set for-sale flag if available from source */
   'also update status from catalog source' => 'UPDATE ctg_upd2 AS i LEFT JOIN ctg_upd1 AS u ON i.IDS_Item=u.IDS_Item
   '2.2 also update status from catalog source'
  SET i.isForSale=i.isForSale OR (u.IDS_Item IS NOT NULL);',
    => 'UPDATE ctg_upd2 AS i LEFT JOIN ctg_upd1 AS u ON i.IDS_Item=u.IDS_Item
      SET i.isForSale=i.isForSale OR (u.IDS_Item IS NOT NULL);',
/* STAGE 3: Update cat_items */
/* STAGE 3: Update cat_items */
   /* -- replace sourced items in cat_items from CTG data (except for fields saved in ctg_upd2) */
   /* -- replace sourced items in cat_items from CTG data (except for fields saved in ctg_upd2) */
   'update item status with calculated items' => 'REPLACE INTO cat_items
   '3.1 update item status with calculated items'
  SELECT *
    => 'REPLACE INTO cat_items
  FROM qryCtg_Upd_join;',
      SELECT *
      FROM qryCtg_Upd_join;',
   /* -- clear availability flags in any unused items */
   /* -- clear availability flags in any unused items */
   'clear availability flags in unused items' => 'UPDATE cat_items AS i LEFT JOIN qryCtg_Upd_join AS u ON i.ID=u.ID SET i.isInPrint=NULL, i.isForSale=NULL WHERE u.ID IS NULL;',
   '3.2 clear availability flags in unused items'
    => 'UPDATE cat_items AS i
      LEFT JOIN qryCtg_Upd_join AS u
ON i.ID=u.ID
SET i.isInPrint=NULL, i.isForSale=NULL WHERE u.ID IS NULL;',
/* NOT FINISHED -- isn't there one more flag? */
/* NOT FINISHED -- isn't there one more flag? */
   /* -- set stock and for-sale fields for *all* joinable cat_items from calculations done in ctg_upd2 */
   /* -- set stock and for-sale fields for *all* joinable cat_items from calculations done in ctg_upd2 */
   'set stock status fields' => 'UPDATE cat_items AS i LEFT JOIN ctg_upd2 AS u ON i.ID=u.ID_Item
   '3.3 set stock status fields'
  SET
    => 'UPDATE cat_items AS i LEFT JOIN ctg_upd2 AS u ON i.ID=u.ID_Item
    i.isForSale=u.isForSale;',
      SET
i.isForSale=u.isForSale;',
   /* -- update inactive catalog numbers where title's catnum has changed */
   /* -- update inactive catalog numbers where title's catnum has changed */
   'update changed inactive catalog numbers' => 'UPDATE cat_items AS i LEFT JOIN qryCat_Titles AS t ON i.ID_Title=t.ID
   '3.4 update changed inactive catalog numbers'
  SET
    => 'UPDATE cat_items AS i LEFT JOIN qryCat_Titles AS t ON i.ID_Title=t.ID
    i.CatNum=CONCAT_WS("-",t.CatNum,i.CatSfx)
      SET
  WHERE (LEFT(i.CatNum,LENGTH(t.CatNum)) != t.CatNum) AND NOT isPulled;',
i.CatNum=CONCAT_WS("-",t.CatNum,i.CatSfx)
      WHERE (LEFT(i.CatNum,LENGTH(t.CatNum)) != t.CatNum) AND NOT isPulled;',
/* STAGE 4: Housekeeping - update timestamp of cat_items so dependent tables will be recalculated */
/* STAGE 4: Housekeeping - update timestamp of cat_items so dependent tables will be recalculated */
   'update cache timestamp' => 'UPDATE data_tables SET WhenUpdated=NOW() WHERE Name="cat_items";'
   '4. update cache timestamp'
  );</php>
    => 'UPDATE data_tables
      SET WhenUpdated=NOW() WHERE Name="cat_items";'
);</php>

Revision as of 23:00, 10 December 2009

About

  • History:
    • 2009-12-10 Transcribed from development source; updated name of source query in STAGE 2; added statement numbers for debugging purposes and changed line formatting for better readability

PHP code

This defines the array which stores the SQL commands to be executed, in order. The key to each array element is the description to be shown to the administrator when executing that command. <php>$arSQL_CtgBuild = array( /* STAGE 1: Clear/refill the two temporary tables from which cat_items is updated. */

 '1.1 clear update table 1 of 2'	=> 'DELETE FROM ctg_upd1;',
 '1.2 clear update table 2 of 2'	=> 'DELETE FROM ctg_upd2;',
 /* == Fill temp tables == */
   /* -- generated source data: */
 '1.3 fill update table 1/2 with source data'
  => 'INSERT INTO ctg_upd1 SELECT

CatSfx, isCloseOut, ID_CTG_Title, ID_CTG_Item, ID_Title, ID_ItTyp, ID_ItOpt, ID_ShipCost, PriceBuy, PriceSell, PriceList, ItOpt_Descr_part, NameSng, GrpItmDescr, TitleGroupDescr, OptionDescr, ItOpt_Sort, GrpCode, GrpDescr, GrpSort, IDS_Item, CatNum, ItOpt_Descr

     FROM qryCtg_src;',
   /* -- existing catalog data indexed for JOINing: */
 '1.4 fill update table 2/2 with pre-join data'
   => 'INSERT INTO ctg_upd2 SELECT *, 0 AS cntDups
     FROM qryCtg_Items_forUpdJoin
     ON DUPLICATE KEY UPDATE cntDups=cntDups+1;',

/* STAGE 2: Calculate stock numbers and set isForSale flag */

  /* -- calculate stock quantities; set for-sale flag if in stock */
 '2.1 calculate stock quantities and status'
   => 'UPDATE ctg_upd2 AS i LEFT JOIN qryStk_items_remaining AS s ON i.ID_Item=s.ID_Item
     SET

i.qtyInStock=s.QtyForSale, i.isForSale=(s.QtyForSale > 0);',

  /* -- also set for-sale flag if available from source */
 '2.2 also update status from catalog source'
   => 'UPDATE ctg_upd2 AS i LEFT JOIN ctg_upd1 AS u ON i.IDS_Item=u.IDS_Item
     SET i.isForSale=i.isForSale OR (u.IDS_Item IS NOT NULL);',

/* STAGE 3: Update cat_items */

  /* -- replace sourced items in cat_items from CTG data (except for fields saved in ctg_upd2) */
 '3.1 update item status with calculated items'
   => 'REPLACE INTO cat_items
     SELECT *
     FROM qryCtg_Upd_join;',
  /* -- clear availability flags in any unused items */
 '3.2 clear availability flags in unused items'
   => 'UPDATE cat_items AS i
     LEFT JOIN qryCtg_Upd_join AS u

ON i.ID=u.ID SET i.isInPrint=NULL, i.isForSale=NULL WHERE u.ID IS NULL;', /* NOT FINISHED -- isn't there one more flag? */

  /* -- set stock and for-sale fields for *all* joinable cat_items from calculations done in ctg_upd2 */
 '3.3 set stock status fields'
   => 'UPDATE cat_items AS i LEFT JOIN ctg_upd2 AS u ON i.ID=u.ID_Item
     SET

i.isForSale=u.isForSale;',

  /* -- update inactive catalog numbers where title's catnum has changed */
 '3.4 update changed inactive catalog numbers'
   => 'UPDATE cat_items AS i LEFT JOIN qryCat_Titles AS t ON i.ID_Title=t.ID
     SET

i.CatNum=CONCAT_WS("-",t.CatNum,i.CatSfx)

     WHERE (LEFT(i.CatNum,LENGTH(t.CatNum)) != t.CatNum) AND NOT isPulled;',

/* STAGE 4: Housekeeping - update timestamp of cat_items so dependent tables will be recalculated */

 '4. update cache timestamp'
   => 'UPDATE data_tables
     SET WhenUpdated=NOW() WHERE Name="cat_items";'

);</php>