コード例 #1
0
 /**
   Scan prodUpdate from dept changes and log them
   in prodDepartmentHistory
   @param $dbc [SQLManager] db connection
   @param $offset [optional int] start scanning from this prodUpdateID
 */
 private function scanDeptChanges($dbc, $offset = 0)
 {
     $prodUpdateQ = 'SELECT prodUpdateID FROM prodUpdate ';
     $args = array();
     if ($offset > 0) {
         $prodUpdateQ .= ' WHERE prodUpdateID > ? ';
         $args[] = $offset;
     }
     $prodUpdateQ .= ' ORDER BY upc, modified';
     $prodUpdateP = $dbc->prepare($prodUpdateQ);
     $prodUpdateR = $dbc->execute($prodUpdateP, $args);
     $chkP = $dbc->prepare("SELECT modified,dept_ID FROM\n            prodDepartmentHistory WHERE upc=?\n            ORDER BY modified DESC");
     $upc = null;
     $prevDept = null;
     $update = new ProdUpdateModel($dbc);
     $history = new ProdDepartmentHistoryModel($dbc);
     /**
         See scanPriceChanges()
     */
     while ($prodUpdateW = $dbc->fetch_row($prodUpdateR)) {
         $update->reset();
         $update->prodUpdateID($prodUpdateW['prodUpdateID']);
         $update->load();
         if ($upc === null || $upc != $update->upc()) {
             $upc = $update->upc();
             $prevDept = null;
             $chkR = $dbc->execute($chkP, array($upc));
             if ($dbc->num_rows($chkR) > 0) {
                 $chkW = $dbc->fetch_row($chkR);
                 $prevDept = $chkW['dept_ID'];
             }
         }
         if ($prevDept != $update->dept()) {
             $history->reset();
             $history->upc($upc);
             $history->storeID($update->storeID());
             $history->modified($update->modified());
             $history->dept_ID($update->dept());
             $history->uid($update->user());
             $history->prodUpdateID($update->prodUpdateID());
             $this->cronMsg('Add dept change #' . $update->prodUpdateID(), FannieLogger::INFO);
             $history->save();
         }
         $prevDept = $update->dept();
     }
 }