Ejemplo n.º 1
0
    list($object_class, $type, $fields) = $_insert;
    $triplets[] = "{$object_class}-{$type}-{$fields}";
}
$where = "CONCAT_WS('-', `object_class`, `type`, `fields`) " . CSQLDataSource::prepareIn($triplets);
$request->addWhere($where);
// Actual query
if ($execute) {
    $query = $request->makeSelect($log);
    $list = $ds->loadList($query);
    $class_to_table = array();
    foreach ($list as $_row) {
        $_object_class = $_row["object_class"];
        $_type = $_row["type"];
        $_fields = $_row["fields"];
        if (!isset($class_to_table[$_object_class])) {
            $_obj = CModelObject::getInstance($_object_class);
            $_spec = $_obj->_spec;
            $class_to_table[$_object_class] = array("table" => $_spec->table, "key" => $_spec->key);
        }
        $_table_info = $class_to_table[$_object_class];
        $_table = $_table_info["table"];
        $_key = $_table_info["key"];
        foreach ($inserts as $_insert) {
            /** @var callable $callback */
            list($object_class, $type, $fields, $callback) = $_insert;
            if ($fields === $_fields && $object_class === $_object_class && $type === $_type) {
                $_query = $callback($ds, $_row);
                $ds->exec($_query);
                $counts["insert"] += $ds->affectedRows();
            }
        }
Ejemplo n.º 2
0
 /**
  * Construit les données afin que celles-ci soient indexées (avec les fields corrects)
  *
  * @param CMbObject $datum The datum you want to construct
  *
  * @return array
  */
 function constructDatum($datum)
 {
     if ($datum['type'] != 'delete') {
         /** @var IIndexableObject|CStoredObject $object */
         $object = CModelObject::getInstance($datum["object_class"]);
         // cas où l'objet a été supprimé avant son indexation en create ou update
         if (!$object->load($datum['object_id'])) {
             $datum_to_index["id"] = $datum['object_id'];
             $datum_to_index["date"] = CMbDT::format(CMbDT::dateTime(), "%Y/%m/%d");
             return $datum_to_index;
         }
         //On récupère les champs à indexer.
         $datum_to_index = $object->getIndexableData();
         if (!$datum_to_index["date"]) {
             $datum_to_index["id"] = $datum['object_id'];
             $datum_to_index["date"] = CMbDT::format(CMbDT::dateTime(), "%Y/%m/%d");
         }
         $datum_to_index['body'] = $this->normalizeEncoding($datum_to_index['body']);
         $datum_to_index['title'] = $this->normalizeEncoding($datum_to_index['title']);
     } else {
         $datum_to_index["id"] = $datum['object_id'];
         $datum_to_index["date"] = CMbDT::format(CMbDT::dateTime(), "%Y/%m/%d");
     }
     return $datum_to_index;
 }