Exemplo n.º 1
1
 public function save($cacheFlag = null)
 {
     if ($this->alias == '') {
         $this->set('alias', $this->generateUniqueAlias($this->name));
     }
     return parent::save($cacheFlag);
 }
 public function save($cacheFlag = null)
 {
     if (empty($this->key)) {
         $this->key = md5($this->id . time() . $this->dir_name);
     }
     return parent::save($cacheFlag);
 }
 public function save($cacheFlag = null)
 {
     if ($isNew = $this->isNew()) {
         /*if(!$this->get('createdon')){
               $this->set('createdon', time());
           }
           
           if(!$this->get('createdby')){
               $this->set('createdby', $this->xpdo->user->id ? $this->xpdo->user->id : null);
           }*/
         $this->set('ip', $this->getUserIP());
     }
     if (!$this->get('parent')) {
         $this->set('parent', null);
     }
     /*
             Не делаем так, потому что иначе при обновлении дочерних комментов
             у нас все родительские комменты будут тоже обновленными
             else{
                 if(!$this->get('editedon')){
                     $this->set('editedon', time());
                 }
             }*/
     $rt = parent::save($cacheFlag);
     /*
         If saved and it`s was new comment, recalculate total comments
     */
     if ($rt && $isNew) {
         $this->recalculateParentComments(1);
     }
     return $rt;
 }
 public function save($cacheFlag = NULL)
 {
     if (!$this->get('topicid') && empty($this->_relatedObjects['Topic']) or !$this->get('blogid') && empty($this->_relatedObjects['Blog'])) {
         return false;
     }
     return parent::save($cacheFlag);
 }
 public function save($cacheFlag = null)
 {
     $preventsave = $this->get('preventsave');
     $published = $this->get('published');
     $this->event = $this->getOne('Event');
     //handle enddate - enddate can't be lower than startdate
     $enddate = $this->get('enddate');
     $startdate = $this->get('startdate');
     if ($enddate <= $startdate) {
         $this->set('enddate', $startdate);
     }
     //handle allday
     $this->handleAllday();
     $active = true;
     if (empty($published)) {
         $active = false;
     }
     if ($active) {
         if (!$this->handleDouble()) {
             return true;
         }
         if (!$this->handleDoubleInAssignedCats()) {
             return true;
         }
     }
     if (!$preventsave) {
         return parent::save($cacheFlag);
     } else {
         return true;
     }
 }
 public function save($cacheFlag = null)
 {
     if ($this->isNew()) {
         $this->set('createdon', strftime('%Y-%m-%d %H:%M:%S'));
     }
     return parent::save($cacheFlag);
 }
Exemplo n.º 7
0
 /**
  * Overrides xPDOObject::save to set the createdon date.
  *
  * {@inheritdoc}
  */
 public function save($cacheFlag = null)
 {
     if ($this->_new && !$this->get('created')) {
         $this->set('created', strftime('%Y-%m-%d %H:%M:%S'));
     }
     $saved = parent::save($cacheFlag);
     return $saved;
 }
Exemplo n.º 8
0
 /**
  * Overrides xPDOObject::save to clear lexicon cache on saving.
  *
  * {@inheritdoc}
  */
 public function save($cacheFlag = null)
 {
     $saved = parent::save($cacheFlag);
     if ($saved && empty($this->xpdo->config[xPDO::OPT_SETUP])) {
         $this->clearCache();
     }
     return $saved;
 }
 public function save($cacheFlag = NULL)
 {
     if (!$this->get('resourceid')) {
         $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Resource ID is null");
         return false;
     }
     return parent::save($cacheFlag);
 }
 public function save($cacheFlag = null)
 {
     if (!$this->Source) {
         $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Attempt to save object without MediaSource: ' . print_r($this->toArray('', true), 1));
         return false;
     }
     $this->path = $this->Source->getPath($this->path);
     return parent::save($cacheFlag);
 }
Exemplo n.º 11
0
 public function save($cacheFlag = null)
 {
     $saved = parent::save($cacheFlag);
     if ($saved) {
         if ($this->xpdo->getCacheManager()) {
             $this->xpdo->cacheManager->delete('gallery/item/list/');
         }
     }
     return $saved;
 }
Exemplo n.º 12
0
 public function save($cacheFlag = null)
 {
     if (!$this->checkDuplicate()) {
         $out = parent::save($cacheFlag);
     } else {
         $this->xpdo->log(xPDO::LOG_LEVEL_INFO, '[ThumbImages] Duplicate records for ' . $this->get('image') . ' with config ' . $this->config);
         $out = false;
     }
     return $out;
 }
Exemplo n.º 13
0
 public function save($cacheFlag = null)
 {
     $update = $this->isDirty('active');
     $save = parent::save($cacheFlag);
     /** @var msdCouponGroup $group */
     if ($update && ($group = $this->getOne('Group'))) {
         $group->updateCounters();
     }
     return $save;
 }
Exemplo n.º 14
0
 /**
  * @param bool $cacheFlag
  * @return bool
  */
 public function save($cacheFlag = false)
 {
     $isNew = $this->isNew();
     if ($isNew) {
         $this->set('createdon', date('Y-m-d H:i:s'));
     } else {
         $this->set('updatedon', date('Y-m-d H:i:s'));
     }
     $saved = parent::save($cacheFlag);
     return $saved;
 }
Exemplo n.º 15
0
 /** 
  * Make sure the relations actually exist.
  */
 public function save($cacheFlag = null)
 {
     if (!($Asset = $this->xpdo->getObject('Asset', $this->get('asset_id')))) {
         $this->xpdo->log(\modX::LOG_LEVEL_ERROR, 'Invalid Asset ID: ' . $this->get('asset_id'), '', __CLASS__);
         throw new \Exception('Invalid Asset ID specified for PageAsset');
     }
     if (!($Page = $this->xpdo->getObject('modResource', $this->get('page_id')))) {
         $this->xpdo->log(\modX::LOG_LEVEL_ERROR, 'Invalid Page ID: ' . $this->get('page_id'), '', __CLASS__);
         throw new \Exception('Invalid Page ID specified for PageAsset');
     }
     return parent::save($cacheFlag);
 }
 public function save($cacheFlag = null)
 {
     if (!$this->User) {
         $this->xpdo->log(xPDO::LOG_LEVEL_WARN, "[- " . __CLASS__ . " -]. User required");
         return false;
     }
     if (!$this->NoticeType) {
         $this->xpdo->log(xPDO::LOG_LEVEL_WARN, "[- " . __CLASS__ . " -]. NoticeType required");
         return false;
     }
     return parent::save($cacheFlag);
 }
Exemplo n.º 17
0
 /**
  * Overrides xPDOObject::save to fire modX-specific events.
  *
  * {@inheritDoc}
  */
 public function save($cacheFlag = null)
 {
     $isNew = $this->isNew();
     if ($this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('OnUserGroupBeforeSave', array('mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD, 'usergroup' => &$this, 'cacheFlag' => $cacheFlag));
     }
     $saved = parent::save($cacheFlag);
     if ($saved && $this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('OnUserGroupSave', array('mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD, 'usergroup' => &$this, 'cacheFlag' => $cacheFlag));
     }
     return $saved;
 }
Exemplo n.º 18
0
 /**
  * Overrides xPDOObject::save to clear lexicon cache on saving.
  *
  * {@inheritdoc}
  */
 public function save($cacheFlag = null)
 {
     if ($this->_new) {
         if (!$this->get('createdon')) {
             $this->set('createdon', strftime('%Y-%m-%d %H:%M:%S'));
         }
     }
     $saved = parent::save($cacheFlag);
     if ($saved && empty($this->xpdo->config[xPDO::OPT_SETUP])) {
         $this->clearCache();
     }
     return $saved;
 }
Exemplo n.º 19
0
 /** {inheritDoc} */
 public function save($cacheFlag = null)
 {
     if ($this->get('email_to') == '') {
         return false;
     }
     $hash = sha1(serialize(array('subscriber_id' => $this->subscriber_id, 'newsletter_id' => $this->newsletter_id, 'email_to' => $this->email_to, 'email_subject' => $this->email_subject, 'email_body' => $this->email_body, 'email_from' => $this->email_from, 'email_from_name' => $this->email_from_name, 'email_reply' => $this->email_reply)));
     if (!$this->xpdo->getCount('sxQueue', array('hash' => $hash))) {
         $this->set('hash', $hash);
         return parent::save($cacheFlag);
     } else {
         return true;
     }
 }
Exemplo n.º 20
0
 public function save($cacheFlag = null)
 {
     /* if the start datetime is empty, should default to right now */
     if (empty($this->start)) {
         $this->start = date("Y-m-d H:i:s");
     }
     /* if the end datetime is empty, shoud default to datetime of its parent event */
     if (empty($this->end)) {
         $event = $this->getOne('Event');
         $this->end = $event->date;
     }
     return parent::save($cacheFlag);
 }
 /**
  * Overrides xPDOObject::save to add edited/created auto-filling fields
  *
  * {@inheritDoc}
  */
 public function save($cacheFlag = null)
 {
     //$now = new DateTime();
     $md5_data = $this->libraryGenerateMD5Data();
     $this->isMD5match = true;
     if (!$this->isNew()) {
         if ($md5_data != $this->get('md5_data')) {
             $this->isMD5match = false;
         }
     } else {
         $this->set('md5_data', $md5_data);
     }
     return parent::save($cacheFlag);
 }
Exemplo n.º 22
0
 public function save($cacheFlag = null)
 {
     if ($this->isNew() && !$this->get('createdon')) {
         $this->set('createdon', strftime('%Y-%m-%d %H:%M:%S'));
     }
     $saved = parent::save($cacheFlag);
     if ($saved) {
         if ($this->xpdo->getCacheManager()) {
             $this->xpdo->cacheManager->delete('gallery/album/' . $this->get('id'));
             $this->xpdo->cacheManager->delete('gallery/album/list/');
             $this->xpdo->cacheManager->delete('gallery/item/list/');
         }
     }
     return $saved;
 }
 public function save($cacheFlag = null)
 {
     if (!$this->getOption(xPDO::OPT_SETUP)) {
         $isNew = $this->isNew();
         if ($isNew) {
             $this->set('created_at', strftime('%Y-%m-%d %H:%M:%S'));
         } else {
             $this->set('updated_at', strftime('%Y-%m-%d %H:%M:%S'));
         }
     }
     $saved = parent::save($cacheFlag);
     if ($saved && !$this->getOption(xPDO::OPT_SETUP)) {
         $this->xpdo->call('modExtensionPackage', 'clearCache', array(&$this->xpdo));
     }
     return $saved;
 }
Exemplo n.º 24
0
 public function save($cacheFlag = null)
 {
     if ($isNew = $this->isNew()) {
         if (!$this->get('createdon')) {
             $this->set('createdon', time());
         }
     }
     /*
             Убираем автоматический апдейт, так как у нас будут сохранения при новых рейтингах и просмотрах
             else{
                 if(!$this->get('editedon')){
                     $this->set('editedon', time());
                 }
             }*/
     return parent::save($cacheFlag);
 }
Exemplo n.º 25
0
 /**
  * {@inheritdoc}
  *
  * All json fields of product are synchronized with msProduct Options
  *
  */
 public function save($cacheFlag = null)
 {
     $save = parent::save();
     $arrays = array();
     foreach ($this->_fieldMeta as $name => $field) {
         if (strtolower($field['phptype']) == 'json') {
             $tmp = $this->get($name);
             if (!empty($tmp) && is_array($tmp)) {
                 $arrays[$name] = $tmp;
             }
         }
     }
     $id = $this->get('id');
     $table = $this->xpdo->getTableName('msProductOption');
     $sql = 'DELETE FROM ' . $table . ' WHERE `product_id` = ' . $id;
     $stmt = $this->xpdo->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $options = $this->get('product_options');
     if (count($options) > 0) {
         foreach ($options as $key => $value) {
             if (!is_array($value)) {
                 $value = array($value);
             }
             $arrays[$key] = $value;
         }
     }
     if (!empty($arrays)) {
         $values = array();
         foreach ($arrays as $key => $tmp) {
             foreach ($tmp as $value) {
                 if (!empty($value) || is_array($options) && array_key_exists($key, $options)) {
                     $values[] = '(' . $id . ',"' . $key . '","' . $value . '")';
                 }
             }
         }
         if (!empty($values)) {
             $sql = 'INSERT INTO ' . $table . ' (`product_id`,`key`,`value`) VALUES ' . implode(',', $values);
             $stmt = $this->xpdo->prepare($sql);
             $stmt->execute();
             $stmt->closeCursor();
         }
     }
     return $save;
 }
Exemplo n.º 26
0
 /**
  * @param null $cacheFlag
  *
  * @return bool
  */
 public function save($cacheFlag = null)
 {
     $coupons = abs($this->get('coupons'));
     if (!$this->isNew()) {
         $children = $this->xpdo->getCount('msdCoupon', array('group_id' => $this->id));
         if ($children < $coupons) {
             $generate = $coupons - $children;
         } else {
             $generate = 0;
         }
     } else {
         $generate = $coupons;
         parent::save($cacheFlag);
     }
     if ($generate > 0) {
         $this->generateCoupons($generate);
     }
     return parent::save();
 }
Exemplo n.º 27
0
 public function save()
 {
     /* when a new event is created, a new default RegType should be created
      * with it as well.
      */
     if ($this->isNew()) {
         $this->xpdo->log(MODx::LOG_LEVEL_INFO, 'Creating default RegType');
         $regtype = $this->xpdo->newObject('RSVPMeRegType');
         $regtype->fromArray(array('name' => 'default', 'description' => 'default registration type', 'code' => isset($this->code) ? $this->code : '', 'fee' => isset($this->fee) ? $this->fee : ''));
         $this->addMany($regtype);
     }
     /**
      * For now, only 1 registration type is allowed, so we will automatically
      * set the end date to the same as the date of the event. It will be set
      * independently in a future release.
      */
     if (!$this->isNew() && $this->isDirty('date')) {
         $regtypes = $this->getMany('RegistrationType');
         $regtype = array_pop($regtypes);
         $regtype->set('end', $this->get('date'));
     }
     /**
      * Since Registration Types will only be editable in a later version,
      * we need to make sure the 'secret code' stays synced
      */
     if (!$this->isNew() && (isset($this->code) || isset($this->fee))) {
         $regtypes = $this->getMany('RegistrationType');
         $regtype = array_pop($regtypes);
         if (isset($this->code)) {
             $regtype->set('code', $this->code);
         }
         if (isset($this->fee)) {
             $regtype->set('fee', $this->fee);
         }
     }
     /* now we can finish saving, this will also save related objects */
     return parent::save();
 }
Exemplo n.º 28
0
 /**
  * @param bool $cacheFlag
  * @return bool
  */
 public function save($cacheFlag = false)
 {
     $isNew = $this->isNew();
     if (!$isNew) {
         return false;
     }
     $this->set('timestamp', time());
     if ($this->xpdo instanceof modX) {
         if (empty($this->xpdo->request)) {
             $this->xpdo->getRequest();
         }
         $this->set('user', $this->xpdo->user->id);
         $this->set('ip', $this->xpdo->request->getClientIp());
     }
     if ($this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('MlmSystemOnLogBeforeSave', array('mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD, 'log' => &$this, 'cacheFlag' => $cacheFlag));
     }
     $saved = parent::save($cacheFlag);
     if ($saved && $this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('MlmSystemOnLogSave', array('mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD, 'log' => &$this, 'cacheFlag' => $cacheFlag));
     }
     return $saved;
 }
Exemplo n.º 29
0
 /**
  * Overrides the xPDOObject::save method to provide custom functionality and
  * automation for the closure tables that persist the board map.
  *
  * @param boolean $cacheFlag
  * @return boolean
  */
 public function save($cacheFlag = null)
 {
     $new = $this->isNew();
     $saved = parent::save($cacheFlag);
     /* if a new board */
     if ($saved && $new) {
         $id = $this->get('id');
         $parent = $this->get('parent');
         /* create self closure */
         $cl = $this->xpdo->newObject('disBoardClosure');
         $cl->set('ancestor', $id);
         $cl->set('descendant', $id);
         if ($cl->save() === false) {
             $this->remove();
             return false;
         }
         /* create closures and calculate rank */
         $tableName = $this->xpdo->getTableName('disBoardClosure');
         $c = $this->xpdo->newQuery('disBoardClosure');
         $c->where(array('descendant' => $parent));
         $c->sortby('depth', 'DESC');
         $gparents = $this->xpdo->getCollection('disBoardClosure', $c);
         $cgps = count($gparents);
         $i = $cgps - 1;
         $gps = array();
         /** @var disBoardClosure $gparent */
         foreach ($gparents as $gparent) {
             $depth = 0;
             $ancestor = $gparent->get('ancestor');
             if ($ancestor != 0) {
                 $depth = $i;
             }
             /** @var disBoardClosure $obj */
             $obj = $this->xpdo->newObject('disBoardClosure');
             $obj->set('ancestor', $ancestor);
             $obj->set('descendant', $id);
             $obj->set('depth', $depth);
             $obj->save();
             $i--;
             $gps[] = $ancestor;
         }
         /* handle 0 ancestor closure */
         $rootcl = $this->xpdo->getObject('disBoardClosure', array('ancestor' => 0, 'descendant' => $id));
         if (!$rootcl) {
             /** @var disBoardClosure $rootcl */
             $rootcl = $this->xpdo->newObject('disBoardClosure');
             $rootcl->set('ancestor', 0);
             $rootcl->set('descendant', $id);
             $rootcl->set('depth', 0);
             $rootcl->save();
         }
         /* set map (allows for 1-query grabbing of all boards while keeping
          * proper sort ordering) */
         $gps[] = $id;
         $map = implode('-', $gps);
         $this->set('map', $map);
         /* set rank to number of boards already with this parent */
         if (!defined('DISCUSS_IMPORT_MODE')) {
             $rank = $this->xpdo->getCount('disBoard', array('parent' => $this->get('parent')));
             $this->set('rank', $rank);
         }
         $saved = parent::save();
     }
     /* if parent changed on existing object, rebuild closure table */
     if (!$new && ($this->parentChanged || $this->categoryChanged)) {
         /* first remove old tree path */
         $c = $this->xpdo->newQuery('disBoardClosure');
         $c->where(array('descendant:=' => $this->get('id'), 'AND:ancestor:!=' => $this->get('id')));
         $rs = $this->xpdo->getCollection('disBoardClosure', $c);
         /** @var disBoardClosure $r */
         foreach ($rs as $r) {
             $r->remove();
         }
         $parents = $this->getRecursiveParentIds();
         array_unshift($parents, $this->get('id'));
         $idx = 0;
         $map = array();
         foreach ($parents as $parent) {
             /** @var disBoardClosure $cl */
             if ($parent == $this->get('id')) {
                 // Do not update own id
                 $idx++;
                 continue;
             }
             $cl = $this->xpdo->newObject('disBoardClosure');
             $cl->set('ancestor', $parent);
             $cl->set('descendant', $this->get('id'));
             $cl->set('depth', $idx);
             $cl->save();
             if ($parent != 0) {
                 array_unshift($map, $parent);
             }
             $idx++;
         }
         $this->set('depth', $idx - 1);
         $this->set('map', implode('.', $map));
         /* save */
         $saved = parent::save();
         // Update children also
         $children = $this->getMany('Children');
         if (count($children) > 0) {
             foreach ($children as $child) {
                 $child->fromArray(array('category' => $this->get('category'), 'parent' => $this->get('id')));
                 $child->forceClosureUpdate();
                 $child->save();
             }
         }
     }
     if ($saved) {
         $this->clearCache();
     }
     return $saved;
 }
Exemplo n.º 30
0
 /**
  * @param null $cacheFlag
  *
  * @return bool
  */
 public function save($cacheFlag = null)
 {
     $save = parent::save($cacheFlag);
     $tags = parent::get('tags');
     if (is_array($tags)) {
         $id = $this->get('id');
         $table = $this->xpdo->getTableName('msResourceFileTag');
         $this->xpdo->exec("DELETE FROM {$table} WHERE `file_id` = {$id};");
         if (!empty($tags)) {
             $values = array();
             foreach ($tags as $tag) {
                 $tag = trim($tag);
                 if (!empty($tag)) {
                     $values[] = '(' . $id . ',"' . $tag . '")';
                 }
             }
             if (!empty($values)) {
                 $this->xpdo->exec("INSERT INTO {$table} (`file_id`,`tag`) VALUES " . implode(',', $values));
             }
         }
     }
     return $save;
 }