Esempio n. 1
0
 /**
  * Delete objects matching the condition array
  * - this is used for processing sync objects and normal delete calls alike
  */
 public static function del($cond, $origin = false, $silent = false)
 {
     $db = JFactory::getDbo();
     $table = self::sqlTable();
     // Make the condition SQL syntax, bail if nothing
     $sqlcond = self::sqlCond($cond);
     if (empty($sqlcond)) {
         return false;
     }
     // TODO: validate cond
     // TODO: check no LG_LOCAL in results
     // Do the deletion
     $db->setQuery("DELETE FROM {$table} WHERE {$sqlcond}");
     $db->query();
     // Add sync object(s) depending on the context of this change
     if (!$silent) {
         LigminchaGlobalSync::create('D', $cond, $origin);
     }
 }
Esempio n. 2
0
 /**
  * Update or create an object in the database and queue the changes if necessary
  * - $origin is passed if this changed arrived from a remote queue
  * - $silent is used to stop any sync objects being generated by the change
  */
 public function update($origin = false, $silent = false)
 {
     $db = JFactory::getDbo();
     $table = LigminchaGlobalDistributed::sqlTable();
     // Bail if no type
     if ($this->type < 1) {
         die('Typeless distributed objects not allowed!');
     }
     // Update an existing object in the database
     if ($this->exists) {
         // TODO: Validate cond
         // Update automatic properties
         $this->flag(LG_NEW, false);
         $this->modified = self::timestamp();
         $sqlVals = $this->sqlValues(false);
         lgDebug('Updating database, object: ' . $this->id);
         $db->setQuery("UPDATE {$table} SET {$sqlVals} WHERE `id`=0x{$this->id}");
         $db->query();
     } else {
         // Only set the automatic properties for locally created non-existent objects
         if (!$origin) {
             $this->flag(LG_NEW, true);
             $this->modified = null;
             $this->creation = self::timestamp();
             // The entry is owned by the user unless it's a server/sync/user object
             if ($this->type == LG_SERVER || $this->type == LG_USER || $this->type == LG_SYNC) {
                 $this->owner = null;
             } else {
                 $this->owner = LigminchaGlobalUser::getCurrent() ? LigminchaGlobalUser::getCurrent()->id : null;
             }
         }
         $sqlVals = $this->sqlValues();
         $db->setQuery("REPLACE INTO {$table} SET {$sqlVals}");
         $db->query();
     }
     // Add outgoing sync objects depending on the context of this change
     // TODO: $private = $this->flag( LG_PRIVATE ) ? $this->owner->server : false
     if (!$silent && !$this->flag(LG_LOCAL)) {
         LigminchaGlobalSync::create('U', $this->fields(), $origin, $private = false);
     }
 }