Beispiel #1
0
 public function insertAll($rows)
 {
     $generic = Factory::getGeneric();
     $rowsSql = array();
     foreach ($rows as $row) {
         $values = array();
         foreach ($row as $name => $value) {
             if (is_null($value)) {
                 $values[] = 'NULL';
             } else {
                 if (is_numeric($value)) {
                     $values[] = $value;
                 } else {
                     if (!ctype_print($value)) {
                         $values[] = $generic->bin2dbRawInsert($value);
                     } else {
                         if (is_bool($value)) {
                             $values[] = $value ? '1' : '0';
                         } else {
                             $values[] = "'{$value}'";
                         }
                     }
                 }
             }
         }
         $rowsSql[] = "(" . implode(',', $values) . ")";
     }
     $sql = 'INSERT INTO ' . $this->table . ' VALUES ' . implode(',', $rowsSql);
     $this->db->query($sql);
 }
Beispiel #2
0
 public function purgeUnused($dimensionMetadataProvider)
 {
     $this->dimensionMetadataProvider = $dimensionMetadataProvider;
     // get current max visit ID in log tables w/ idaction references.
     $maxIds = $this->getMaxIdsInLogTables();
     $this->generic = Factory::getGeneric($this->db);
     $this->createTempTable();
     // do large insert (inserting everything before maxIds) w/o locking tables...
     $this->insertActionsToKeep($maxIds, $deleteOlderThanMax = true);
     // ... then do small insert w/ locked tables to minimize the amount of time tables are locked.
     $this->generic->beginTransaction();
     $this->lockLogTables($this->generic);
     $this->insertActionsToKeep($maxIds, $deleteOlderThanMax = false);
     // Mysql uses 'INSERT IGNORE' which is not available on pgsql 9.1.
     // We can do the generic->insertIgnore, but checking for exception for every
     // single query can be a time taking endeavour. To avoid, 'INSERT's are
     // carried on normally. Before deleting unused actions, we will remove
     // duplicate rows from the temporary table.
     $this->deleteDuplicatesFromTempTable();
     // delete before unlocking tables so there's no chance a new log row that references an
     // unused action will be inserted.
     $this->deleteUnusedActions();
     // unlock the log tables. In pgsql, locks are released on commit/rollback
     $this->generic->commit();
     $this->generic = null;
 }
 public function updateConversions($values, $idvisit)
 {
     $Generic = Factory::getGeneric($this->db);
     $binary_columns = array('idvisitor');
     foreach ($binary_columns as $bc) {
         if (array_key_exists($bc, $values)) {
             $values[$bc] = $Generic->bin2db($values[$bc]);
         }
     }
     $updateParts = $sqlBind = array();
     foreach ($values as $name => $value) {
         // Case where bind parameters don't work
         if (strpos($value, $name) !== false) {
             //$name = 'visit_total_events'
             //$value = 'visit_total_events + 1';
             $updateParts[] = " {$name} = {$value} ";
         } else {
             $updateParts[] = $name . " = ?";
             $sqlBind[] = $value;
         }
     }
     array_push($sqlBind, $idvisit);
     $sql = 'UPDATE ' . $this->table . ' SET ' . implode(', ', $updateParts) . ' ' . 'WHERE idvisit = ?';
     $result = $this->db->query($sql, $sqlBind);
 }
 /**
  *  uses tracker db
  */
 public function insertNew($goal)
 {
     $Generic = Factory::getGeneric($this->db);
     // pg is throwing error when empty values are given for 'FLOAT' columns
     if (empty($goal['revenue'])) {
         unset($goal['revenue']);
     }
     if (empty($goal['revenue_subtotal'])) {
         unset($goal['revenue_subtotal']);
     }
     if (empty($goal['revenue_tax'])) {
         unset($goal['revenue_tax']);
     }
     if (empty($goal['revenue_shipping'])) {
         unset($goal['revenue_shipping']);
     }
     if (empty($goal['revenue_discount'])) {
         unset($goal['revenue_discount']);
     }
     $fields = implode(', ', array_keys($goal));
     $bindFields = Common::getSqlStringFieldsArray($goal);
     $goal['idvisitor'] = $Generic->bin2db($goal['idvisitor']);
     $sql = 'INSERT INTO ' . $this->table . '( ' . $fields . ' ) ' . 'VALUES ( ' . $bindFields . ' ) ';
     $bind = array_values($goal);
     $result = $Generic->insertIgnore($sql, $bind);
     return $result;
 }
Beispiel #5
0
 /**
  * @param $select
  * @param $from
  */
 protected function updateQuerySelectFromForSiteSearch(&$select, &$from)
 {
     $Generic = Factory::getGeneric();
     $max_col = $Generic->castToNumeric('log_link_visit_action.custom_var_v' . ActionSiteSearch::CVAR_INDEX_SEARCH_COUNT);
     $selectFlagNoResultKeywords = ",\n            CASE WHEN (MAX({$max_col}) = 0\n                  AND MAX(log_link_visit_action.custom_var_k" . ActionSiteSearch::CVAR_INDEX_SEARCH_COUNT . ") = '" . ActionSiteSearch::CVAR_KEY_SEARCH_COUNT . "')\n              THEN 1 \n              ELSE 0\n            END AS " . $this->db->quoteIdentifier(PiwikMetrics::INDEX_SITE_SEARCH_HAS_NO_RESULT);
     //we need an extra JOIN to know whether the referrer "idaction_name_ref" was a Site Search request
     $from[] = array("table" => "log_action", "tableAlias" => "log_action_name_ref", "joinOn" => "log_link_visit_action.idaction_name_ref = log_action_name_ref.idaction");
     $selectPageIsFollowingSiteSearch = ",\n            SUM( CASE WHEN log_action_name_ref.type = " . Action::TYPE_SITE_SEARCH . " \n                    THEN 1 ELSE 0 END) \n               AS " . $this->db->quoteIdentifier(PiwikMetrics::INDEX_PAGE_IS_FOLLOWING_SITE_SEARCH_NB_HITS) . " ";
     $select .= $selectFlagNoResultKeywords . $selectPageIsFollowingSiteSearch;
 }
 /**
  * Performs a batch insert into a specific table by iterating through the data
  *
  * NOTE: you should use tableInsertBatch() which will fallback to this function if LOAD DATA INFILE not available
  *
  * @param string $tableName PREFIXED table name! you must call Common::prefixTable() before passing the table name
  * @param array $fields array of unquoted field names
  * @param array $values array of data to be inserted
  * @param bool $ignoreWhenDuplicate Ignore new rows that contain unique key values that duplicate old rows
  */
 public static function tableInsertBatchIterate($tableName, $fields, $values, $ignoreWhenDuplicate = true)
 {
     $isArchive = strpos($tableName, 'archive');
     if ($isArchive === false) {
         $Generic = Factory::getGeneric();
         $Generic->insertIgnoreBatch($tableName, $fields, $values, $ignoreWhenDuplicate);
     } else {
         // archive_blob_* tables need special handling for the "value" column
         $Archive = Factory::getDAO('archive');
         $Archive->insertIgnoreBatch($tableName, $fields, $values, $ignoreWhenDuplicate);
     }
 }
Beispiel #7
0
 function __construct($processor)
 {
     parent::__construct($processor);
     if ($processor->getParams()->getSite()->isEcommerceEnabled()) {
         $this->maximumRowsInDataTableLevelZero = self::MAX_ROWS_WHEN_ECOMMERCE;
         $this->maximumRowsInSubDataTable = self::MAX_ROWS_WHEN_ECOMMERCE;
     } else {
         $this->maximumRowsInDataTableLevelZero = Config::getInstance()->General['datatable_archiving_maximum_rows_custom_variables'];
         $this->maximumRowsInSubDataTable = Config::getInstance()->General['datatable_archiving_maximum_rows_subtable_custom_variables'];
     }
     $this->Generic = Factory::getGeneric();
 }
Beispiel #8
0
 protected function invalidatedArchiveIdRows($archiveTable, $idSites)
 {
     $sql = "SELECT idsite, date1, date2, period, name,\n                       STRING_AGG(idarchive || '.' || value, ','  ORDER BY ts_archived DESC) as archives\n                  FROM {$archiveTable}\n                 WHERE name LIKE 'done%'\n                   AND value IN (" . ArchiveWriter::DONE_INVALIDATED . ',' . ArchiveWriter::DONE_OK . ',' . ArchiveWriter::DONE_OK_TEMPORARY . ")\n                   AND idsite IN (" . implode(',', $idSites) . ")\n                 GROUP BY idsite, date1, date2, period, name";
     $rows = $this->db->fetchAll($sql);
     if ($this->isBlob($archiveTable)) {
         $Generic = Factory::getGeneric();
         foreach ($rows as &$row) {
             $parts = explode('.', $row['archives']);
             $row['archives'] = $parts[0] . '.' . $Generic->db2bin($parts[1]);
         }
     }
     return $rows;
 }
 /**
  * Records the layout in the DB for the given user.
  *
  * @param string $login
  * @param int $idDashboard
  * @param string $layout
  */
 public function saveLayout($login, $idDashboard, $layout)
 {
     $generic = Factory::getGeneric($this->db);
     $sql = 'SELECT * FROM ' . $this->table . ' ' . 'WHERE login = ? AND iddashboard = ? FOR UPDATE';
     $row = $this->db->query($sql, array($login, $idDashboard));
     if ($row) {
         $sql = 'UPDATE ' . $this->table . ' SET ' . ' layout = ? ' . 'WHERE login = ? AND iddashboard = ?';
         $bind = array($layout, $login, $idDashboard);
     } else {
         $sql = 'INSERT INTO ' . $this->table . '(login, iddashboard, layout) ' . 'VALUES (?, ?, ?)';
         $bind = array($login, $idDashboard, $layout);
     }
     $this->db->query($sql, $bind);
 }
 public function setForUser($login, $languageCode)
 {
     $generic = Factory::getGeneric($this->db);
     $generic->beginTransaction();
     $sql = 'SELECT login, language FROM ' . $this->table . ' ' . 'WHERE login = ?';
     $row = $this->db->fetchRow($sql, array($login));
     if ($row) {
         $sql = 'UPDATE ' . $this->table . ' SET ' . ' language = ? ' . 'WHERE login = ?';
         $this->db->query($sql, array($languageCode, $login));
     } else {
         $this->db->insert($this->table, array('login' => $login, 'language' => $languageCode));
     }
     $generic->commit();
 }
 /**
  *  recordProfiling
  *
  *  Makes an entry in the table for the query if query does not exist.
  *  If the query exists, the row will be update.
  *  The query column has a unique key.
  *  Uses tracker db
  *  @param string $query
  *  @param int    $count
  *  @param string $time
  *  @return void
  */
 public function recordProfiling($query, $count, $time)
 {
     $generic = Factory::getGeneric($this->db);
     $generic->beginTransaction();
     $sql = 'SELECT query, count, sum_time_ms ' . 'FROM ' . $this->table . ' ' . 'WHERE query = ? FOR UPDATE';
     $row = $this->db->fetchOne($sql, array($query));
     if ($row) {
         $sql = 'UPDATE ' . $this->table . ' SET ' . " count = count + {$count}, sum_time_ms = sum_time_msg + {$time} " . 'WHERE query = ?';
         $this->db->query($sql, array($query));
     } else {
         $sql = 'INSERT INTO ' . $this->table . '(query, count, sum_time_ms) ' . "VALUES (?, ?, ?)";
         $this->db->query($sql, array($query, $count, $time));
     }
     $generic->commit();
 }
Beispiel #12
0
 /**
  * Get / allocate / reserve a new id for the current sequence. Important: Getting the next id will fail in case
  * no such sequence exists. Make sure to create one if needed, see {@link create()}.
  *
  * @return int
  * @throws Exception
  */
 public function getNextId()
 {
     $Generic = Factory::getGeneric($this->db);
     $Generic->beginTransaction();
     $sql = 'UPDATE ' . $this->table . ' SET value = value + 1 WHERE name = ?';
     $result = $this->db->query($sql, array($this->name));
     $rowCount = $result->rowCount();
     if (1 !== $rowCount) {
         $Generic->rollback();
         throw new \Exception("Sequence '" . $this->name . "' not found.");
     }
     $createdId = $this->getCurrentId();
     $Generic->commit();
     return (int) $createdId;
 }
 public function fetchAll()
 {
     $generic = Factory::getGeneric();
     $generic->checkByteaOutput();
     $sql = 'SELECT *, idvisitor::text AS idvisitor_text FROM ' . $this->table;
     $rows = $this->db->fetchAll($sql);
     while (list($k, $row) = each($rows)) {
         if (!empty($row['idvisitor'])) {
             $rows[$k]['idvisitor'] = $generic->db2bin($row['idvisitor_text']);
         }
         unset($rows[$k]['idvisitor_text']);
     }
     reset($rows);
     return $rows;
 }
Beispiel #14
0
 public function upsert($idSite, $settingName, $settingValue)
 {
     $Generic = Factory::getGeneric();
     $Generic->beginTransaction();
     $sql = "SELECT * FROM {$this->table} WHERE idsite = ? AND setting_name = ? FOR UPDATE";
     $row = $this->db->fetchOne($sql, array($idSite, $settingName));
     if ($row) {
         $sql = "UPDATE {$this->table} SET\n                    setting_value = ?\n                    WHERE idsite = ? AND setting_name = ?";
         $this->db->query($sql, array($settingValue, $idSite, $settingName));
     } else {
         $sql = "INSERT INTO {$this->table} (idsite, setting_name, setting_value) VALUES (?, ?, ?)";
         $this->db->query($sql, array($idSite, $settingName, $settingValue));
     }
     $Generic->commit();
 }
Beispiel #15
0
 public function addRecord($name, $value, $autoload)
 {
     $generic = Factory::getGeneric($this->db);
     $generic->beginTransaction();
     $sql = 'SELECT * FROM ' . $this->table . ' WHERE option_name = ?';
     $row = $this->db->fetchOne($sql, array($name));
     if ($row) {
         $sql = 'UPDATE ' . $this->table . ' SET option_value = ? ' . 'WHERE option_name = ?';
         $bind = array($value, $name);
     } else {
         $sql = 'INSERT INTO ' . $this->table . ' (option_name, option_value, autoload) ' . 'VALUES (?, ?, ?) ';
         $bind = array($name, $value, $autoload);
     }
     $this->db->query($sql, $bind);
     $generic->commit();
 }
Beispiel #16
0
 public function createConversion($conversion)
 {
     $fields = implode(", ", array_keys($conversion));
     $bindFields = Common::getSqlStringFieldsArray($conversion);
     $table = Common::prefixTable('log_conversion');
     $db = $this->getDb();
     $Generic = Factory::getGeneric($db);
     $sql = "INSERT INTO {$table} ({$fields}) VALUES ({$bindFields}) ";
     if (!empty($conversion['idvisitor'])) {
         $conversion['idvisitor'] = $Generic->bin2db($conversion['idvisitor']);
     }
     $bind = array_values($conversion);
     $result = $Generic->insertIgnore($sql, $bind);
     // If a record was inserted, we return true
     return $db->rowCount($result) > 0;
 }
Beispiel #17
0
 /**
  * Write Session - commit data to resource
  *
  * @param string $id
  * @param mixed $data
  * @param integer $maxLifetime
  * @return boolean
  */
 public function write($id, $data, $maxLifetime)
 {
     $Generic = Factory::getGeneric();
     $sql = 'SELECT ' . $this->config['dataColumn'] . ' FROM ' . $this->config['name'] . ' WHERE ' . $this->config['primary'] . ' = ? FOR UPDATE';
     $Generic->beginTransaction();
     $row = $this->db->fetchOne($sql, array($id));
     if ($row) {
         $sql = 'UPDATE ' . $this->config['name'] . ' SET ' . $this->config['modifiedColumn'] . ' = ?,' . $this->config['lifetimeColumn'] . ' = ?,' . $this->config['dataColumn'] . ' = ? ' . ' WHERE ' . $this->config['primary'] . ' = ?';
         $values = array(time(), $maxLifetime, $data, $id);
     } else {
         $sql = 'INSERT INTO ' . $this->config['name'] . ' (' . $this->config['primary'] . ',' . $this->config['modifiedColumn'] . ',' . $this->config['lifetimeColumn'] . ',' . $this->config['dataColumn'] . ')' . ' VALUES (?,?,?,?)';
         $values = array($id, time(), $maxLifetime, $data);
     }
     $this->db->query($sql, $values);
     $Generic->commit();
     return true;
 }
Beispiel #18
0
 /**
  * Sets the language for the user
  *
  * @param string $login
  * @param string $languageCode
  * @return bool
  */
 public function setLanguageForUser($login, $languageCode)
 {
     $Generic = Factory::getGeneric();
     $Generic->beginTransaction();
     $sql = 'SELECT * FROM ' . $this->table . ' WHERE login = ? FOR UPDATE';
     $row = $this->db->query($sql, array($login));
     if ($row) {
         $sql = 'UPDATE ' . $this->table . ' SET language = ? WHERE login = ?';
         $bind = array($languageCode, $login);
     } else {
         $sql = 'INSERT INTO ' . $this->table . ' (login, language) VALUES (?, ?)';
         $bind = array($login, $languageCode);
     }
     $this->db->query($sql, $bind);
     $Generic->commit();
     return true;
 }
 protected function paramsRecord($idvisit, $idsite, $idvisitor, $server_time, $url, $name, $ref_url, $ref_name, $time_spent, $custom_value, $custom_variables, $actionIdsCached)
 {
     $Generic = Factory::getGeneric($this->db);
     $insert = array('idvisit' => $idvisit, 'idsite' => $idsite, 'idvisitor' => $Generic->bin2db($idvisitor), 'server_time' => $server_time, 'idaction_url' => $url, 'idaction_name' => $name, 'idaction_url_ref' => $ref_url, 'idaction_name_ref' => $ref_name, 'time_spent_ref_action' => $time_spent);
     $integerCols = array('idsite', 'idvisit', 'idaction_url', 'idaction_url_ref', 'idaction_name', 'idaction_name_ref', 'idaction_event_category', 'idaction_event_action', 'time_spent_ref_action');
     foreach ($actionIdsCached as $field => $idAction) {
         if (in_array($field, $integerCols) && is_bool($idAction)) {
             $insert[$field] = (int) $idAction;
         } else {
             $insert[$field] = $idAction;
         }
     }
     if (!empty($custom_value)) {
         $insert[Action::DB_COLUMN_CUSTOM_FLOAT] = $custom_value;
     }
     $insert = array_merge($insert, $custom_variables);
     $fields = implode(', ', array_keys($insert));
     $bind = array_values($insert);
     $values = Common::getSqlStringFieldsArray($insert);
     $sql = 'INSERT INTO ' . $this->table . '( ' . $fields . ') VALUES ( ' . $values . ')';
     return array($sql, $bind, $insert);
 }
Beispiel #20
0
 /**
  * Checks whether the database user is allowed to lock tables.
  *
  * @return bool
  */
 public static function isLockPrivilegeGranted()
 {
     if (is_null(self::$lockPrivilegeGranted)) {
         $generic = Factory::getGeneric();
         self::$lockPrivilegeGranted = $generic->isLockPrivilegeGranted();
     }
     return self::$lockPrivilegeGranted;
 }
Beispiel #21
0
 protected function adjacentVisitorId($idSite, $visitorId, $visitLastActionTime, $segment, $getNext)
 {
     if ($getNext) {
         $visitLastActionTimeCondition = "sub.visit_last_action_time <= ?";
         $orderByDir = "DESC";
     } else {
         $visitLastActionTimeCondition = "sub.visit_last_action_time >= ?";
         $orderByDir = "ASC";
     }
     $visitLastActionDate = Date::factory($visitLastActionTime);
     $dateOneDayAgo = $visitLastActionDate->subDay(1);
     $dateOneDayInFuture = $visitLastActionDate->addDay(1);
     $Generic = Factory::getGeneric();
     $bin_idvisitor = $Generic->binaryColumn('log_visit.idvisitor');
     $select = "{$bin_idvisitor}, MAX(log_visit.visit_last_action_time) as visit_last_action_time";
     $from = "log_visit";
     $where = "log_visit.idsite = ? AND log_visit.idvisitor <> ? AND visit_last_action_time >= ? and visit_last_action_time <= ?";
     $whereBind = array($idSite, $visitorId, $dateOneDayAgo->toString('Y-m-d H:i:s'), $dateOneDayInFuture->toString('Y-m-d H:i:s'));
     $orderBy = "MAX(log_visit.visit_last_action_time) {$orderByDir}";
     $groupBy = "log_visit.idvisitor";
     $segment = new Segment($segment, $idSite);
     $queryInfo = $segment->getSelectQuery($select, $from, $where, $whereBind, $orderBy, $groupBy);
     $sql = "SELECT sub.idvisitor, sub.visit_last_action_time\n                  FROM ({$queryInfo['sql']}) as sub\n                 WHERE {$visitLastActionTimeCondition}\n                 LIMIT 1";
     $bind = array_merge($queryInfo['bind'], array($visitLastActionTime));
     return $this->db->fetchOne($sql, $bind);
 }
 /**
  * Executes and returns a query aggregating ecommerce item data (everything stored in the
  * **log\_conversion\_item** table)  and returns a DB statement that can be used to iterate over the result
  *
  * <a name="queryEcommerceItems-result-set"></a>
  * **Result Set**
  *
  * Each row of the result set represents an aggregated group of ecommerce items. The following
  * columns are in each row of the result set:
  *
  * - **{@link Piwik\Metrics::INDEX_ECOMMERCE_ITEM_REVENUE}**: The total revenue for the group of items.
  * - **{@link Piwik\Metrics::INDEX_ECOMMERCE_ITEM_QUANTITY}**: The total number of items in this group.
  * - **{@link Piwik\Metrics::INDEX_ECOMMERCE_ITEM_PRICE}**: The total price for the group of items.
  * - **{@link Piwik\Metrics::INDEX_ECOMMERCE_ORDERS}**: The total number of orders this group of items
  *                                                      belongs to. This will be <= to the total number
  *                                                      of items in this group.
  * - **{@link Piwik\Metrics::INDEX_NB_VISITS}**: The total number of visits that caused these items to be logged.
  * - **ecommerceType**: Either {@link Piwik\Tracker\GoalManager::IDGOAL_CART} if the items in this group were
  *                      abandoned by a visitor, or {@link Piwik\Tracker\GoalManager::IDGOAL_ORDER} if they
  *                      were ordered by a visitor.
  *
  * **Limitations**
  *
  * Segmentation is not yet supported for this aggregation method.
  *
  * @param string $dimension One or more **log\_conversion\_item** columns to group aggregated data by.
  *                          Eg, `'idaction_sku'` or `'idaction_sku, idaction_category'`.
  * @return \Zend_Db_Statement A statement object that can be used to iterate through the query's
  *                           result set. See [above](#queryEcommerceItems-result-set) to learn more
  *                           about what this query selects.
  * @api
  */
 public function queryEcommerceItems($dimension)
 {
     #$LogConversionItem = Factory::getDAO('log_conversion_item');
     #return $LogConversionItem->getEcommerceItems($dimension, $this->getBindDatetimeSite());
     $Generic = Factory::getGeneric();
     $ecommerceType = $this->db->quoteIdentifier('ecommerceType');
     $query = $this->generateQuery(implode(', ', array("log_action.name AS label", sprintf("log_conversion_item.%s AS labelIdAction", $dimension), sprintf('%s AS ' . $this->db->quoteIdentifier('%d') . ' ', $Generic->getSqlRevenue('SUM(log_conversion_item.quantity * log_conversion_item.price)'), Metrics::INDEX_ECOMMERCE_ITEM_REVENUE), sprintf('%s AS ' . $this->db->quoteIdentifier('%d') . ' ', $Generic->getSqlRevenue('SUM(log_conversion_item.quantity)'), Metrics::INDEX_ECOMMERCE_ITEM_QUANTITY), sprintf('%s AS ' . $this->db->quoteIdentifier('%d') . ' ', $Generic->getSqlRevenue('SUM(log_conversion_item.price)'), Metrics::INDEX_ECOMMERCE_ITEM_PRICE), sprintf('COUNT(distinct log_conversion_item.idorder) AS ' . $this->db->quoteIdentifier('%d') . ' ', Metrics::INDEX_ECOMMERCE_ORDERS), sprintf('COUNT(distinct log_conversion_item.idvisit) AS ' . $this->db->quoteIdentifier('%d') . ' ', Metrics::INDEX_NB_VISITS), sprintf("CASE log_conversion_item.idorder WHEN '0' THEN %d ELSE %d END AS {$ecommerceType}", GoalManager::IDGOAL_CART, GoalManager::IDGOAL_ORDER))), array("log_conversion_item", array("table" => "log_action", "joinOn" => sprintf("log_conversion_item.%s = log_action.idaction", $dimension))), implode(' AND ', array('log_conversion_item.server_time >= ?', 'log_conversion_item.server_time <= ?', 'log_conversion_item.idsite IN (' . Common::getSqlStringFieldsArray($this->sites) . ')', 'log_conversion_item.deleted = 0')), sprintf("{$ecommerceType}, label, log_conversion_item.%s", $dimension), false);
     return $this->getDb()->query($query['sql'], $query['bind']);
 }
 protected function getItemRowEnriched($goal, $item)
 {
     $Generic = Factory::getGeneric($this->db);
     $class = '\\Piwik\\Tracker\\GoalManager';
     $newRow = array('idaction_sku' => (int) $item[$class::INTERNAL_ITEM_SKU], 'idaction_name' => (int) $item[$class::INTERNAL_ITEM_NAME], 'idaction_category' => (int) $item[$class::INTERNAL_ITEM_CATEGORY], 'idaction_category2' => (int) $item[$class::INTERNAL_ITEM_CATEGORY2], 'idaction_category3' => (int) $item[$class::INTERNAL_ITEM_CATEGORY3], 'idaction_category4' => (int) $item[$class::INTERNAL_ITEM_CATEGORY4], 'idaction_category5' => (int) $item[$class::INTERNAL_ITEM_CATEGORY5], 'price' => $item[$class::INTERNAL_ITEM_PRICE], 'quantity' => $item[$class::INTERNAL_ITEM_QUANTITY], 'deleted' => isset($item['deleted']) ? $item['deleted'] : 0, 'idorder' => isset($goal['idorder']) ? $goal['idorder'] : $class::ITEM_IDORDER_ABANDONED_CART, 'idsite' => $goal['idsite'], 'idvisitor' => $Generic->bin2db($goal['idvisitor']), 'server_time' => $goal['server_time'], 'idvisit' => $goal['idvisit']);
     return $newRow;
 }
Beispiel #24
0
 protected function getMaxIdsInLogTables()
 {
     $Generic = Factory::getGeneric($this->db);
     $result = array();
     foreach ($this->getTableIdColumns() as $table => $col) {
         $result[$table] = $Generic->getMax(Common::prefixTable($table), $col);
     }
     return $result;
 }
Beispiel #25
0
 public function deletePreviousArchiveStatus($numericTable, $archiveId, $doneFlag)
 {
     $dbLockName = "deletePreviousArchiveStatus.{$numericTable}.{$archiveId}";
     // without advisory lock here, the DELETE would acquire Exclusive Lock
     $Generic = Factory::getGeneric();
     $Generic->getDbLock($dbLockName);
     $this->db->query("DELETE FROM {$numericTable} WHERE idarchive = ? AND (name = '" . $doneFlag . "')", array($archiveId));
     $Generic->releaseDbLock($dbLockName);
 }
Beispiel #26
0
 protected function visitFieldsToQuery($valuesToUpdate)
 {
     $Generic = Factory::getGeneric($this->getDb());
     $updateParts = array();
     $sqlBind = array();
     foreach ($valuesToUpdate as $name => $value) {
         // Case where bind parameters don't work
         if ($value === $name . ' + 1') {
             //$name = 'visit_total_events'
             //$value = 'visit_total_events + 1';
             $updateParts[] = " {$name} = {$value} ";
         } else {
             $updateParts[] = $name . " = ?";
             if ($name == 'idvisitor') {
                 $sqlBind[] = $Generic->bin2db($value);
             } else {
                 $sqlBind[] = $value;
             }
         }
     }
     return array($updateParts, $sqlBind);
 }
Beispiel #27
0
 protected function prepareForBinary($table)
 {
     $this->Generic = Factory::getGeneric($this->db);
     $this->isBlobTable = $this->isBlob($table);
     $this->Generic->checkByteaOutput();
     $valueCol = $this->isBlobTable ? $this->Generic->binaryColumn('value') : ' value ';
     return $valueCol;
 }
Beispiel #28
0
 public function insertIgnoreBatch($tableName, $fields, $values, $ignoreWhenDuplicate)
 {
     $Generic = Factory::getGeneric($this->db);
     $Generic->insertIgnoreBatch($tableName, $fields, $values, $ignoreWhenDuplicate);
 }
 private function getLogTableDeleteCount($table, $maxIdVisit)
 {
     $Generic = Factory::getGeneric();
     return $Generic->getCountFromWhere($table, array('idvisit <= ?' => $maxIdVisit));
 }
Beispiel #30
0
 public function deleteGoalConversions($idSite, $idGoal)
 {
     $table = Common::prefixTable("log_conversion");
     $Generic = Factory::getGeneric($this->db);
     $Generic->deleteAll($table, "WHERE idgoal = ? AND idsite = ?", "idvisit", 100000, array($idGoal, $idSite));
 }