class_Lock.inc 12.05 KiB
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2003-2010  Cajus Pollmeier
  Copyright (C) 2011-2020  FusionDirectory
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 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 General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
class Lock
  public $dn;
  public $objectDn;
  public $userDn;
  public $timestamp;
  public function __construct (string $dn, string $objectDn, string $userDn, DateTime $timestamp)
    $this->dn         = $dn;
    $this->objectDn   = $objectDn;
    $this->userDn     = $userDn;
    $this->timestamp  = $timestamp;
  /*!
   *  \brief Add a lock for object(s)
   * Adds a lock by the specified user for one ore multiple objects.
   * If a lock for that object already exists from another user, an error is triggered.
   * \param array $object The object or array of objects to lock
   * \param string $user  The user who shall own the lock
  public static function add ($object, string $user = NULL)
    global $config, $ui;
    /* Remember which entries were opened as read only, because we
        don't need to remove any locks for them later */
    if (!session::is_set('LOCK_CACHE')) {
      session::set('LOCK_CACHE', ['']);
    if (is_array($object)) {
      foreach ($object as $obj) {
        static::add($obj, $user);
      return;
    if ($user === NULL) {
      $user = $ui->dn;
    $cache = &session::get_ref('LOCK_CACHE');
    if (isset($_POST['open_readonly'])) {
      $cache['READ_ONLY'][$object] = TRUE;
      return;