/** * Add a lock to the Resource while unpublishing it * @return boolean */ public function addLock() { $locked = $this->resource->addLock(); if ($locked !== true) { $user = $this->modx->getObject('modUser', $locked); if ($user) { $locked = false; } } return $locked; }
/** * Add a lock to the resource we are saving * @return boolean */ public function addLock() { $locked = $this->object->addLock(); if ($locked !== true) { $stealLock = $this->getProperty('steal_lock', false); if (!empty($stealLock)) { if (!$this->modx->hasPermission('steal_locks') || !$this->object->checkPolicy('steal_lock')) { return false; } if ($locked > 0 && $locked != $this->modx->user->get('id')) { $this->object->removeLock($locked); $locked = $this->object->addLock($this->modx->user->get('id')); } } if ($locked !== true) { $lockedBy = intval($locked); $this->lockedUser = $this->modx->getObject('modUser', $lockedBy); if ($this->lockedUser) { $locked = false; } else { $this->object->removeLock($lockedBy); $locked = true; } } } return $locked; }
/** * {@inheritDoc} * @return mixed */ public function afterSave() { $this->object->addLock(); $this->setParentToContainer(); $this->saveResourceGroups(); $this->checkIfSiteStart(); return parent::afterSave(); }
/** * Check for locks on the Resource * * @return bool */ public function checkForLocks() { $lockedBy = $this->resource->addLock($this->modx->user->get('id')); $this->canSave = $this->modx->hasPermission('save_document') ? 1 : 0; $this->locked = false; $this->lockedText = ''; if (!empty($lockedBy) && $lockedBy !== true) { $this->canSave = false; $this->locked = true; $locker = $this->modx->getObject('modUser', $lockedBy); if ($locker) { $lockedBy = $locker->get('username'); } $this->lockedText = $this->modx->lexicon('resource_locked_by', array('user' => $lockedBy, 'id' => $this->resource->get('id'))); } return $this->locked; }