Esempio n. 1
0
 public function delete()
 {
     $tableName = Inflection::pluralise($this->getTableName(false) . '_' . $this->getTextMapperTableAppend());
     $connection = $this->conn();
     $connection->query(ParseQuery::parse($connection, "DELETE FROM %T WHERE %C = %d", $tableName, 'source_id', $this->id()));
     parent::delete();
 }
Esempio n. 2
0
 public static function getAll($query)
 {
     $contactSelect = self::_getDisplayResultPattern("c", "name");
     $campaignsSelect = self::_getDisplayResultPattern("C", "name");
     $queryData = ["SELECT * FROM (\n        (SELECT {$contactSelect}, %C, 'Contact' as `type` FROM %T WHERE %C LIKE %~)\n        UNION ALL\n        (SELECT {$campaignsSelect}, %C, 'Campaign' as `type` FROM %T WHERE %C LIKE %~ OR %C LIKE %~)\n        ) %T ORDER BY %C", "name", Contact::tableName(), "name", $query, "name", Campaign::tableName(), "name", $query, "label", $query, "temp", "name"];
     $results = DB::getAccessor("defero_db")->getRows(ParseQuery::parse(DB::getAccessor("defero_db"), $queryData));
     return $results;
 }
Esempio n. 3
0
 /**
  * @return BucketRange
  */
 protected function _claimNextFreeRange()
 {
     $range = false;
     $db = BucketRange::conn();
     EventManager::trigger(Events::CLAIM_RANGE_START);
     // Check for an already-flagged range
     $coll = new RecordCollection(new BucketRange());
     $coll->loadWhere(['processing' => 1, 'hostname' => $this->_hostname, 'instanceName' => $this->_instanceName])->limit(1);
     if ($coll->count() > 0) {
         $range = $coll->first();
     } else {
         $res = $db->query(ParseQuery::parse($db, "UPDATE %T SET processing=1, hostname=%s, instanceName=%s " . "WHERE processing=0 AND processed=0 ORDER BY randomKey LIMIT 1", BucketRange::tableName(), $this->_hostname, $this->_instanceName));
         if ($res) {
             $range = BucketRange::loadWhere(['processing' => 1, 'hostname' => $this->_hostname, 'instanceName' => $this->_instanceName]);
         }
     }
     EventManager::trigger(Events::CLAIM_RANGE_END);
     return $range;
 }
Esempio n. 4
0
 private static function _listRangesWhere($where, $limit = 0)
 {
     $query = "SELECT prefix, updatedAt, hostname, error FROM %T " . "WHERE " . $where;
     if ($limit > 0) {
         $query .= " LIMIT " . $limit;
     }
     $db = BucketRange::conn();
     $ranges = $db->getRows(ParseQuery::parse($db, $query, BucketRange::tableName()));
     $numRanges = count($ranges);
     if ($numRanges > 0) {
         $table = new TextTable();
         $table->setColumnHeaders('prefix', 'updatedAt', 'hostname', 'error');
         foreach ($ranges as $range) {
             $table->appendRow([$range->prefix, $range->updatedAt, $range->hostname, $range->error]);
         }
         echo $table;
     }
     return $numRanges;
 }
Esempio n. 5
0
 protected function _multiGetRows(IDatabaseService $db, $query, $tables, $limit = 0)
 {
     $result = [];
     foreach ($tables as $table) {
         $res = $db->getRows(ParseQuery::parse($db, $query, $table));
         $result = array_merge($result, $res);
         $numResults = count($result);
         if ($limit > 0 && $numResults >= $limit) {
             if ($numResults > $limit) {
                 $result = array_slice($result, 0, $limit);
             }
             break;
         }
     }
     return $result;
 }