Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

db.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 3.30 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  namespace phpbb\lock;
015   
016  /**
017  * Database locking class
018  */
019  class db
020  {
021      /**
022      * Name of the config variable this lock uses
023      * @var string
024      */
025      private $config_name;
026   
027      /**
028      * Unique identifier for this lock.
029      *
030      * @var string
031      */
032      private $unique_id;
033   
034      /**
035      * Stores the state of this lock
036      * @var bool
037      */
038      private $locked;
039   
040      /**
041      * The phpBB configuration
042      * @var \phpbb\config\config
043      */
044      private $config;
045   
046      /**
047      * A database connection
048      * @var \phpbb\db\driver\driver_interface
049      */
050      private $db;
051   
052      /**
053      * Creates a named released instance of the lock.
054      *
055      * You have to call acquire() to actually create the lock.
056      *
057      * @param    string                                $config_name    A config variable to be used for locking
058      * @param    \phpbb\config\config                $config            The phpBB configuration
059      * @param    \phpbb\db\driver\driver_interface    $db                A database connection
060      */
061      public function __construct($config_name, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db)
062      {
063          $this->config_name = $config_name;
064          $this->config = $config;
065          $this->db = $db;
066      }
067   
068      /**
069      * Tries to acquire the lock by updating
070      * the configuration variable in the database.
071      *
072      * As a lock may only be held by one process at a time, lock
073      * acquisition may fail if another process is holding the lock
074      * or if another process obtained the lock but never released it.
075      * Locks are forcibly released after a timeout of 1 hour.
076      *
077      * @return    bool            true if lock was acquired
078      *                            false otherwise
079      */
080      public function acquire()
081      {
082          if ($this->locked)
083          {
084              return false;
085          }
086   
087          if (!isset($this->config[$this->config_name]))
088          {
089              $this->config->set($this->config_name, '0', false);
090          }
091          $lock_value = $this->config[$this->config_name];
092   
093          // make sure lock cannot be acquired by multiple processes
094          if ($lock_value)
095          {
096              // if the other process is running more than an hour already we have to assume it
097              // aborted without cleaning the lock
098              $time = explode(' ', $lock_value);
099              $time = $time[0];
100   
101              if ($time + 3600 >= time())
102              {
103                  return false;
104              }
105          }
106   
107          $this->unique_id = time() . ' ' . unique_id();
108   
109          // try to update the config value, if it was already modified by another
110          // process we failed to acquire the lock.
111          $this->locked = $this->config->set_atomic($this->config_name, $lock_value, $this->unique_id, false);
112   
113          if ($this->locked == true)
114          {
115              if ($this->config->ensure_lock($this->config_name, $this->unique_id))
116              {
117                  return true;
118              }
119          }
120          return $this->locked;
121      }
122   
123      /**
124      * Does this process own the lock?
125      *
126      * @return    bool            true if lock is owned
127      *                            false otherwise
128      */
129      public function owns_lock()
130      {
131          return (bool) $this->locked;
132      }
133   
134      /**
135      * Releases the lock.
136      *
137      * The lock must have been previously obtained, that is, acquire() call
138      * was issued and returned true.
139      *
140      * Note: Attempting to release a lock that is already released,
141      * that is, calling release() multiple times, is harmless.
142      *
143      * @return null
144      */
145      public function release()
146      {
147          if ($this->locked)
148          {
149              $this->config->set_atomic($this->config_name, $this->unique_id, '0', false);
150              $this->locked = false;
151          }
152      }
153  }
154