Ejemplo n.º 1
0
	
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Affero General Public License for more details.
	
	You should have received a copy of the GNU Affero General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'class.tlondata.php';
TlonMessage::$TABLE = new TlonDataTable('tl_message', 'message_id, username, document_id, arrival_time, operations, applied');
class TlonMessage
{
    public static $TABLE = null;
    public static function add($username, $document_id, $operations, $applied = false)
    {
        return TlonData::insert(self::$TABLE, array(null, $username, $document_id, time(), $operations, $applied ? 1 : 0));
    }
    public static function getUnappliedByDocumentID($document_id)
    {
        return TlonData::selectConds(self::$TABLE, array(TlonDataComparison::equals('document_id', $document_id), TlonDataComparison::equals('applied', 0)));
    }
    public static function getByArrivalTimeAfter($document_id, $time, $username)
    {
        return TlonData::selectConds(self::$TABLE, array(TlonDataComparison::equals('document_id', $document_id), TlonDataComparison::greaterThan('arrival_time', $time), TlonDataComparison::notEquals('username', $username)));
    }
Ejemplo n.º 2
0
 private function integrateMessages($document_id)
 {
     $dbg = array('docid' => $document_id);
     if (($msgs = TlonMessage::getUnappliedByDocumentID($document_id)) && ($doc = $this->_get($document_id))) {
         $dbg['num_messages'] = count($msgs);
         $wd = new WootDocument(new WootID(0, 0), $doc['title'], array_map(array($this, 'arrToWootChar'), $doc['content']));
         $dbg['before'] = $this->unserialize($doc['content']);
         foreach ($msgs as $msg) {
             $applied = true;
             $ops = $this->unserialize($msg['operations']);
             foreach ($ops as $op) {
                 $r = $op['op'] == WootMessage::OP_DEL ? $wd->integrateDelete($this->arrToWootChar($op['char'])) : $wd->integrateInsert($this->arrToWootChar($op['char']), $this->arrToWootChar($op['prev']), $this->arrToWootChar($op['next']));
                 if ($r === false) {
                     $applied = false;
                 }
             }
             if ($applied) {
                 TlonMessage::setApplied($msg['message_id']);
             }
         }
         $dbg['after'] = array_map(array($this, 'wootCharToArr'), $wd->content());
         $doc['content'] = $this->serialize(array_map(array($this, 'wootCharToArr'), $wd->content()));
         $dbg['res'] = TlonDocument::update($document_id, $doc['title'], $doc['content'], $doc['parent']);
     }
     $this->cleanMessages($document_id);
     return $dbg;
 }