Пример #1
0
 /**
  * Copies the data from one table to another.
  * If the source table has more columns than the destination table,
  * the copy still happens just without that data being transferred.
  *
  * @param string $source
  * @param string $destination
  * @param array $renameColumns [sourceColName => destColName, ...] Needed if you're copying from one table to another where the column names differ
  * @return boolean
  */
 protected function copyTable($source, $destination, $renameColumns = array())
 {
     $this->expectTables(array($source, $destination), "Can't copy table");
     $sourceCols = $this->fields($source);
     $destCols = $this->fields($destination);
     // Only copy columns that exist in both tables
     $columnsInSourceNotInDest = array_diff($sourceCols, $destCols);
     foreach ($columnsInSourceNotInDest as $unsetColumn) {
         if (!isset($renameColumns[$unsetColumn])) {
             $key = array_search($unsetColumn, $sourceCols);
             unset($sourceCols[$key]);
         }
     }
     // As long as we select the fields from the $source table that are in the $dest table,
     // we shouldn't run into any errors.
     $sourceSelects = array_combine($sourceCols, $sourceCols);
     // Rename any columns
     if (count($renameColumns)) {
         foreach ($renameColumns as $sourceCol => $destCol) {
             $this->expectColumn($source, $sourceCol, "When copying table {$source} to {$destination}, can't rename column {$sourceCol} to {$destCol} because {$sourceCol} does not exist.");
             $this->expectColumn($destination, $destCol, "When copying table {$source} to {$destination}, can't rename column {$sourceCol} to {$destCol} because {$destCol} does not exist.");
             if (!isset($sourceSelects[$sourceCol])) {
                 $this->log("Tried to rename a column that won't be used when copying table {$source} to {$destination}.");
                 continue;
             }
             $sourceSelects[$sourceCol] = "{$sourceCol} AS {$destCol}";
         }
     }
     $select = implode(', ', $sourceSelects);
     $sourceRows = $this->db->exec_SELECTgetRows($select, $source, '');
     if (!count($sourceRows)) {
         $this->success("Nothing to copy from {$source} to {$destination}");
         return TRUE;
     }
     $this->db->exec_INSERTmultipleRows($destination, array_keys($sourceRows[0]), $sourceRows);
     $this->success("Copied table from {$source} to {$destination}.");
     return TRUE;
 }
 /**
  * Add initial static data (standing: 2016-02-18)
  */
 private function addInitialStaticData()
 {
     /**
      * Import products static data
      */
     $this->databaseConnection->exec_INSERTmultipleRows('tx_projectregistration_domain_model_product', ['uid', 'pid', 'title', 'properties', 'sorting', 'tstamp', 'crdate', 'cruser_id'], [[1, 1, 'i.roc® Ci70 -Ex', 1, 512, 0, 0, 0], [2, 1, 'i.roc® Ci70 -Ex RFID LF', 1, 768, 0, 0, 0], [3, 1, 'i.roc® Ci70 -Ex RFID HF', 1, 1024, 0, 0, 0], [4, 1, 'i.roc® Ci70 -Ex RFID UHF US', 1, 1280, 0, 0, 0], [5, 1, 'i.roc® Ci70 -Ex RFID UHF', 1, 1536, 0, 0, 0], [6, 1, 'i.roc® Ci70 -Ex 1D Barcode', 1, 1792, 0, 0, 0], [7, 1, 'i.roc® Ci70 -Ex 2D EX25', 1, 2048, 0, 0, 0], [8, 1, 'i.roc® Ci70 -Ex Combi Reader LF/ 1D', 1, 2304, 0, 0, 0], [9, 1, 'i.roc® Ci70 -Ex Combi Reader HF/ 1D', 1, 2560, 0, 0, 0], [10, 1, 'Getac V100-Ex2, Standard', 0, 2816, 0, 0, 0], [11, 1, 'Getac V100-Ex2, Premium', 0, 3072, 0, 0, 0], [12, 1, 'Z710-Ex Basic', 0, 3328, 0, 0, 0], [13, 1, 'Z710-Ex Basic 1D/2D Barcode', 0, 3584, 0, 0, 0], [14, 1, 'Z710-Ex Basic HF RFID', 0, 3840, 0, 0, 0], [15, 1, 'Z710-Ex Basic 1D/2D + HF RFID', 0, 4096, 0, 0, 0], [16, 1, 'Z710-Ex Premium', 0, 4352, 0, 0, 0], [17, 1, 'Z710-Ex Premium 1D/2D', 0, 4608, 0, 0, 0], [18, 1, 'Z710-Ex Premium HF RFID', 0, 4864, 0, 0, 0], [19, 1, 'Z710-Ex Premium 1D/2D + HF RFID', 0, 5120, 0, 0, 0], [20, 1, 'CK70 ATEX', 0, 5376, 0, 0, 0], [21, 1, 'CK71 ATEX', 0, 5632, 0, 0, 0], [22, 1, 'CN70A ATEX', 0, 5888, 0, 0, 0], [23, 1, 'CN70E ATEX', 0, 6144, 0, 0, 0], [24, 1, 'Tab-Ex® Zone 1', 1, 6400, 0, 0, 0], [25, 1, 'Tab-Ex® Division 1', 1, 6656, 0, 0, 0], [26, 1, 'Tab-Ex® Zone 2', 1, 6912, 0, 0, 0], [27, 1, 'Tab-Ex® Division 2', 1, 7168, 0, 0, 0], [28, 1, 'Smart-Ex® 01 EU no camera', 0, 7424, 0, 0, 0], [29, 1, 'Smart-Ex® 01 EU camera', 0, 7680, 0, 0, 0], [30, 1, 'Smart-Ex® 01 US no camera', 0, 7936, 0, 0, 0], [31, 1, 'Smart-Ex® 01 US camera', 0, 8192, 0, 0, 0], [32, 1, 'Smart-Ex® 201 EU no camera', 0, 8448, 0, 0, 0], [33, 1, 'Smart-Ex® 201 EU camera', 0, 8704, 0, 0, 0], [34, 1, 'Smart-Ex® 201 US camera', 0, 8960, 0, 0, 0], [35, 1, 'Smart-Ex® 201 US no camera', 0, 9216, 0, 0, 0], [36, 1, 'Ex-Handy 09 Zone 1 EU', 0, 9472, 0, 0, 0], [37, 1, 'Ex-Handy 09 Div 1 US', 0, 9728, 0, 0, 0], [38, 1, 'Ex-Handy 209 EU', 0, 9984, 0, 0, 0], [39, 1, 'Ex-Handy 209 US', 0, 10240, 0, 0, 0], [40, 1, 'others', 0, 10496, 0, 0, 0]]);
     $this->feedback .= $this->renderFlashMessage('Added static data to \'tx_projectregistration_domain_model_product\'', 'Static data imported!');
     /**
      * Import product properties static data
      */
     $this->databaseConnection->exec_INSERTmultipleRows('tx_projectregistration_domain_model_productproperty', ['uid', 'pid', 'title', 'form_element_type', 'sorting', 'tstamp', 'crdate', 'cruser_id'], [[1, 1, 'WWAN', 0, 0, 0, 0, 0], [2, 1, 'LTE', 0, 0, 0, 0, 0]]);
     $this->feedback .= $this->renderFlashMessage('Added static data to \'tx_projectregistration_domain_model_productproperty\'', 'Static data imported!');
     /**
      * Import product property values static data
      */
     $this->databaseConnection->exec_INSERTmultipleRows('tx_projectregistration_domain_model_productpropertyvalue', ['uid', 'pid', 'title', 'sorting', 'tstamp', 'crdate', 'cruser_id', 'property'], [[1, 1, 'Yes', 0, 0, 0, 0, 1], [2, 1, 'No', 0, 0, 0, 0, 1], [3, 1, 'Yes', 0, 0, 0, 0, 2], [4, 1, 'No', 0, 0, 0, 0, 2]]);
     $this->feedback .= $this->renderFlashMessage('Added static data to \'tx_projectregistration_domain_model_productpropertyvalue\'', 'Static data imported!');
     /**
      * Import product <> property MM-relations
      */
     $this->databaseConnection->exec_INSERTmultipleRows('tx_projectregistration_product_property_mm', ['uid_local', 'uid_foreign', 'sorting', 'sorting_foreign'], [[1, 1, 1, 0], [2, 1, 1, 0], [3, 1, 1, 0], [4, 1, 1, 0], [5, 1, 1, 0], [6, 1, 1, 0], [7, 1, 1, 0], [8, 1, 1, 0], [9, 1, 1, 0], [24, 2, 1, 0], [25, 2, 1, 0], [26, 2, 1, 0], [27, 2, 1, 0]]);
     $this->feedback .= $this->renderFlashMessage('Added product <> property MM-relations to \'tx_projectregistration_product_property_mm\'', 'Static data imported!');
 }