public function _migrateData(\b2db\Table $old_table)
 {
     $sqls = array();
     $tn = $this->_getTableNameSQL();
     $qc = $this->getQC();
     switch ($old_table->getVersion()) {
         case 1:
             $sqls[] = "UPDATE {$tn} SET icon = itemdata";
             $sqls[] = "UPDATE {$tn} SET {$qc}key{$qc} = NULL";
             break;
     }
     foreach ($sqls as $sql) {
         $statement = \b2db\Statement::getPreparedStatement($sql);
         $res = $statement->performQuery('update');
     }
     switch ($old_table->getVersion()) {
         case 1:
             foreach (self::getTable()->getAll() as $issuetype) {
                 // Trigger issuetype key regeneration
                 $issuetype->setKey(null);
                 $issuetype->getKey();
                 $issuetype->save();
             }
             break;
     }
 }
 public function _migrateData(\b2db\Table $old_table)
 {
     $sqls = array();
     $tn = $this->_getTableNameSQL();
     switch ($old_table->getVersion()) {
         case 1:
             $sqls[] = "UPDATE {$tn} SET owner_team = owner WHERE owner_type = 2";
             $sqls[] = "UPDATE {$tn} SET owner_user = owner WHERE owner_type = 1";
             $sqls[] = "UPDATE {$tn} SET assignee_team = assigned_to WHERE assigned_type = 2";
             $sqls[] = "UPDATE {$tn} SET assignee_user = assigned_to WHERE assigned_type = 1";
             $sqls[] = "UPDATE {$tn} SET name = title";
             break;
     }
     foreach ($sqls as $sql) {
         $statement = \b2db\Statement::getPreparedStatement($sql);
         $res = $statement->performQuery('update');
     }
 }
Esempio n. 3
0
 /**
  * Register a new SQL call (debug only)
  *
  * @param Statement $statement
  * @param mixed $pretime
  */
 public static function sqlHit(Statement $statement, $pretime)
 {
     if (!Core::isDebugMode()) {
         return;
     }
     $time = Core::getDebugTime() - $pretime;
     $sql = $statement->printSQL();
     $values = $statement->getCriteria() instanceof Criteria ? $statement->getCriteria()->getValues() : array();
     $trace = self::getRelevantDebugBacktraceElement();
     self::$_sqlhits[] = array('sql' => $sql, 'values' => implode(', ', $values), 'time' => $time, 'filename' => $trace['file'], 'line' => $trace['line'], 'function' => $trace['function'], 'class' => isset($trace['class']) ? $trace['class'] : 'unknown', 'type' => isset($trace['type']) ? $trace['type'] : 'unknown', 'arguments' => $trace['args']);
     self::$_sqltiming += $time;
 }
Esempio n. 4
0
 public function getByUserIDAndGroupableMinutes($user_id, $minutes = 0)
 {
     if ($minutes <= 0 || !is_numeric($minutes)) {
         return $this->getByUserID($user_id);
     }
     $notification_type_issue_updated_col = \thebuggenie\core\entities\Notification::TYPE_ISSUE_UPDATED;
     $seconds = $minutes * 60;
     list($target_id_col, $notification_type_col, $module_name_col, $is_read_col, $created_at_col, $triggered_by_user_id_col, $user_id_col, $scope_col, $id_col) = $this->getAliasColumns();
     $sql = 'SELECT ';
     $sql_selects = array();
     foreach ($this->getAliasColumns() as $column) {
         $sql_selects[] = $column . ' AS ' . str_replace('.', '_', $column);
     }
     $sql .= join(', ', $sql_selects);
     $sql .= ", (CASE WHEN {$notification_type_col} = '{$notification_type_issue_updated_col}' THEN 1 ELSE {$id_col} END) as {$this->b2db_alias}_custom_group_by";
     $sql .= ' FROM ' . Core::getTablePrefix() . $this->getB2DBName() . ' ' . $this->getB2DBAlias();
     $sql .= " WHERE {$user_id_col} = {$user_id} AND {$triggered_by_user_id_col} != {$user_id}";
     $sql .= " GROUP BY {$this->b2db_alias}_custom_group_by, {$created_at_col} DIV {$seconds}, {$triggered_by_user_id_col}";
     $sql .= " ORDER BY {$id_col} DESC";
     $crit = $this->getCriteria();
     $crit->sql = $sql;
     $crit->action = 'select';
     $statement = \b2db\Statement::getPreparedStatement($crit);
     $resultset = $statement->performQuery();
     return $this->_populateFromResultset($resultset->count() ? $resultset : null);
 }
Esempio n. 5
0
 public function markUserNotificationsReadByTypesAndIdAndGroupableMinutes($types, $id, $user_id, $minutes = 0, $is_read = 1, $mark_all = true)
 {
     if (!is_array($types)) {
         $types = array($types);
     }
     $notification_type_issue_updated_col = \thebuggenie\core\entities\Notification::TYPE_ISSUE_UPDATED;
     if (($key = array_search($notification_type_issue_updated_col, $types)) === false || ($minutes <= 0 || !is_numeric($minutes))) {
         if (!$mark_all) {
             return;
         }
         return $this->markUserNotificationsReadByTypesAndId($types, $id, $user_id);
     }
     $cols = array_map(function ($col) {
         return str_replace(self::B2DBNAME . '.', '', $col);
     }, array('id' => self::ID, 'target_id' => self::TARGET_ID, 'created_at' => self::CREATED_AT, 'is_read' => self::IS_READ, 'notification_type' => self::NOTIFICATION_TYPE, 'user_id' => self::USER_ID, 'scope' => self::SCOPE));
     $b2dbname = \b2db\Core::getTablePrefix() . self::B2DBNAME;
     $seconds = $minutes * 60;
     $scope = framework\Context::getScope()->getID();
     $sub_sql = "SELECT {$cols['id']}, {$cols['target_id']}, ({$cols['created_at']} DIV {$seconds}) AS created_at_div FROM {$b2dbname} WHERE ";
     if (is_array($id)) {
         $sub_sql .= $cols['target_id'] . ' IN (' . implode(', ', $id) . ')';
     } else {
         $sub_sql .= "{$cols['target_id']} = {$id}";
     }
     $sql = "UPDATE {$b2dbname} a JOIN ({$sub_sql}) b ON a.{$cols['id']} = b.{$cols['id']} SET a.{$cols['is_read']} = {$is_read} WHERE (a.{$cols['notification_type']} = '{$notification_type_issue_updated_col}') AND (a.{$cols['user_id']} = {$user_id}) AND (a.{$cols['scope']} = {$scope}) AND ((a.{$cols['created_at']} DIV {$seconds}) * a.{$cols['created_at']} DIV (a.{$cols['created_at']})) IN (b.created_at_div)";
     $crit = $this->getCriteria();
     $crit->sql = $sql;
     $crit->action = 'update';
     $statement = \b2db\Statement::getPreparedStatement($crit);
     $statement->performQuery();
     if (!$mark_all) {
         return;
     }
     unset($types[$key]);
     $this->markUserNotificationsReadByTypesAndId($types, $id, $user_id);
 }