Remove old spider related classes and database columns/tables
authorCyperghost <olaf_schmitz_1@t-online.de>
Tue, 27 Feb 2024 11:22:28 +0000 (12:22 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Tue, 27 Feb 2024 11:22:28 +0000 (12:22 +0100)
24 files changed:
XSD/spiderList.xsd [deleted file]
com.woltlab.wcf/cronjob.xml
com.woltlab.wcf/templates/usersOnlineList.tpl
wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.1_spider_step1.php [new file with mode: 0644]
wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.1_spider_step2.php [new file with mode: 0644]
wcfsetup/install/files/lib/action/AbstractOauth2Action.class.php
wcfsetup/install/files/lib/action/TwitterAuthAction.class.php
wcfsetup/install/files/lib/data/session/Session.class.php
wcfsetup/install/files/lib/data/spider/Spider.class.php [deleted file]
wcfsetup/install/files/lib/data/spider/SpiderAction.class.php [deleted file]
wcfsetup/install/files/lib/data/spider/SpiderEditor.class.php [deleted file]
wcfsetup/install/files/lib/data/spider/SpiderList.class.php [deleted file]
wcfsetup/install/files/lib/data/user/online/UserOnline.class.php
wcfsetup/install/files/lib/data/user/online/UsersOnlineList.class.php
wcfsetup/install/files/lib/page/UserPage.class.php
wcfsetup/install/files/lib/page/UsersOnlineListPage.class.php
wcfsetup/install/files/lib/system/cache/builder/SpiderCacheBuilder.class.php [deleted file]
wcfsetup/install/files/lib/system/cronjob/RefreshSearchRobotsCronjob.class.php [deleted file]
wcfsetup/install/files/lib/system/session/SessionHandler.class.php
wcfsetup/install/files/lib/system/spider/Spider.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/spider/SpiderHandler.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/visitTracker/VisitTracker.class.php
wcfsetup/install/files/lib/util/HeaderUtil.class.php
wcfsetup/setup/db/install.sql

diff --git a/XSD/spiderList.xsd b/XSD/spiderList.xsd
deleted file mode 100644 (file)
index 3bd8cec..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0"?>
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.woltlab.com" targetNamespace="http://www.woltlab.com" elementFormDefault="qualified">
-       <!-- include types -->
-       <xs:include schemaLocation="types.xsd" />
-
-       <!-- data element -->
-       <xs:element name="data">
-               <xs:complexType>
-                       <xs:sequence>
-                               <xs:element name="spider" type="spider" minOccurs="0" maxOccurs="unbounded" />
-                       </xs:sequence>
-               </xs:complexType>
-       </xs:element>
-
-       <!-- spider element type -->
-       <xs:complexType name="spider">
-               <xs:attribute name="ident" type="woltlab_varchar" />
-               <xs:complexContent>
-                       <xs:all>
-                               <xs:element name="name" type="woltlab_varchar" minOccurs="1" />
-                               <xs:element name="url" type="woltlab_varchar" minOccurs="0" />
-                       </xs:all>
-               </xs:complexContent>
-       </xs:complexType>
-</xs:schema>
index 9b68d8b149732ea5fcc358870297d5084fc39ff1..a8c24c94f65322f62f25c647c702a9d0bdde4160 100644 (file)
@@ -8,12 +8,6 @@
                        <expression type="random">@daily</expression>
                        <canbedisabled>0</canbedisabled>
                </cronjob>
-               <cronjob name="com.woltlab.wcf.refreshSearchRobots">
-                       <classname>wcf\system\cronjob\RefreshSearchRobotsCronjob</classname>
-                       <description>Refreshes list of search robots</description>
-                       <description language="de">Aktualisiert die Liste der Suchroboter</description>
-                       <expression type="random">@monthly</expression>
-               </cronjob>
                <cronjob name="com.woltlab.wcf.dailyCleanUp">
                        <classname>wcf\system\cronjob\DailyCleanUpCronjob</classname>
                        <description>Executes daily Cleanup</description>
                        <canbedisabled>0</canbedisabled>
                </cronjob>
        </import>
+       <delete>
+               <cronjob name="com.woltlab.wcf.refreshSearchRobots">
+                       <classname>wcf\system\cronjob\RefreshSearchRobotsCronjob</classname>
+               </cronjob>
+       </delete>
 </data>
index 3c4a9a2b84222a5d3b4f9cd0d75f332f9dbc971d..700aafe7282ba682a2189370548f719809af5c7e 100644 (file)
@@ -91,8 +91,8 @@
                        <dl class="plain inlineDataList small">
                                <dt>{lang}wcf.user.usersOnline.ipAddress{/lang}</dt>
                                <dd title="{$user->getFormattedIPAddress()}">{@$user->getFormattedIPAddress()|ipSearch}</dd>
-                               
-                               {if !$user->spiderID}
+
+                               {if !$user->spiderIdentifier}
                                        <dt>{lang}wcf.user.usersOnline.userAgent{/lang}</dt>
                                        <dd title="{$user->userAgent}">{$user->getBrowser()|truncate:30}</dd>
                                {/if}
                {/capture}
                
                {assign var=usersOnline value=$usersOnline+1}
-       {elseif $user->spiderID}
+       {elseif $user->spiderIdentifier}
                {* search robot *}
                {capture append=robotsOnlineList}
                        <li>
                                        
                                        <div class="details userInformation">
                                                <div class="containerHeadline">
-                                                       <h3>{if $user->getSpider()->spiderURL}<a {anchorAttributes url=$user->getSpider()->spiderURL}>{$user->getSpider()->spiderName}</a>{else}{$user->getSpider()->spiderName}{/if}</h3>
+                                                       <h3>{if $user->getSpider()->url}
+                                                                       <a {anchorAttributes url=$user->getSpider()->url}>{$user->getSpider()->name}</a>{else}{$user->getSpider()->name}{/if}
+                                                       </h3>
                                                        {@$locationData}
                                                </div>
                                                
diff --git a/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.1_spider_step1.php b/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.1_spider_step1.php
new file mode 100644 (file)
index 0000000..1218e6e
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * Drops old spider related columns and index from `wcf1_session` table.
+ *
+ * @author      Olaf Braun
+ * @copyright   2001-2024 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ */
+
+use wcf\system\database\table\column\IntDatabaseTableColumn;
+use wcf\system\database\table\index\DatabaseTableForeignKey;
+use wcf\system\database\table\index\DatabaseTableIndex;
+use wcf\system\database\table\PartialDatabaseTable;
+
+return [
+    PartialDatabaseTable::create('wcf1_session')
+        ->columns([
+            IntDatabaseTableColumn::create('spiderID')
+                ->length(10)
+                ->drop(),
+        ])
+        ->indices([
+            DatabaseTableIndex::create('packageID')
+                ->columns(['lastActivityTime', 'spiderID'])
+                ->drop(),
+        ])
+        ->foreignKeys([
+            DatabaseTableForeignKey::create()
+                ->columns(['spiderID'])
+                ->referencedTable('wcf1_spider')
+                ->referencedColumns(['spiderID'])
+                ->onDelete('CASCADE')
+                ->drop(),
+        ]),
+];
diff --git a/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.1_spider_step2.php b/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.1_spider_step2.php
new file mode 100644 (file)
index 0000000..eb0ac66
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+/**
+ * Drops olds `wcf1_spider` table and create new columns to identify spiders in `wcf1_session` table.
+ *
+ * @author      Olaf Braun
+ * @copyright   2001-2024 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ */
+
+use wcf\system\database\table\column\VarcharDatabaseTableColumn;
+use wcf\system\database\table\index\DatabaseTableIndex;
+use wcf\system\database\table\PartialDatabaseTable;
+
+return [
+    PartialDatabaseTable::create('wcf1_spider')
+        ->drop(),
+    PartialDatabaseTable::create('wcf1_session')
+        ->columns([
+            VarcharDatabaseTableColumn::create('spiderIdentifier')
+                ->length(191)
+                ->defaultValue(null),
+        ])
+        ->indices([
+            DatabaseTableIndex::create('packageID')
+                ->columns(['lastActivityTime', 'spiderIdentifier']),
+        ]),
+];
index 03be86dd657373cdd88e9d0e96742e5f92e729b3..5c54d33385fc2418513638f72fcf413d0368b4cf 100644 (file)
@@ -41,7 +41,7 @@ abstract class AbstractOauth2Action extends AbstractAction
     {
         parent::readParameters();
 
-        if (WCF::getSession()->spiderID) {
+        if (WCF::getSession()->spiderIdentifier) {
             throw new PermissionDeniedException();
         }
     }
index 6867a0f4f15c0fb701e940fd1a1fbc56e2c15508..4c7d37d4d26651136ed384c5dc43365b56b724f7 100644 (file)
@@ -47,7 +47,7 @@ final class TwitterAuthAction extends AbstractAction
     {
         parent::readParameters();
 
-        if (WCF::getSession()->spiderID) {
+        if (WCF::getSession()->spiderIdentifier) {
             throw new PermissionDeniedException();
         }
     }
index 74c34e5c79d0df439f1b42b2078ee3ba7dd16d5a..99ce86472e816278c2bf66f8d2bef2c856884a0e 100644 (file)
@@ -15,7 +15,7 @@ use wcf\data\acp\session\ACPSession;
  * @property-read   int|null $pageObjectID       id of the object the latest page visited belongs to
  * @property-read   int|null $parentPageID       id of the parent page of latest page visited
  * @property-read   int|null $parentPageObjectID id of the object the parent page of latest page visited belongs to
- * @property-read   int $spiderID       id of the spider the session belongs to
+ * @property-read   int $spiderIdentifier identifier of the spider
  */
 class Session extends ACPSession
 {
diff --git a/wcfsetup/install/files/lib/data/spider/Spider.class.php b/wcfsetup/install/files/lib/data/spider/Spider.class.php
deleted file mode 100644 (file)
index 76e1848..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-namespace wcf\data\spider;
-
-use wcf\data\DatabaseObject;
-
-/**
- * Represents a spider.
- *
- * @author  Alexander Ebert
- * @copyright   2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- *
- * @property-read   int $spiderID       unique id of the spider
- * @property-read   string $spiderIdentifier   unique textual identifier of the spider
- * @property-read   string $spiderName     name of the spider
- * @property-read   string $spiderURL      link to the spider's website or empty if no such website exists
- */
-class Spider extends DatabaseObject
-{
-}
diff --git a/wcfsetup/install/files/lib/data/spider/SpiderAction.class.php b/wcfsetup/install/files/lib/data/spider/SpiderAction.class.php
deleted file mode 100644 (file)
index 60bfbc1..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php
-
-namespace wcf\data\spider;
-
-use wcf\data\AbstractDatabaseObjectAction;
-
-/**
- * Executes spider-related actions.
- *
- * @author  Alexander Ebert
- * @copyright   2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- *
- * @method  Spider      create()
- * @method  SpiderEditor[]  getObjects()
- * @method  SpiderEditor    getSingleObject()
- */
-class SpiderAction extends AbstractDatabaseObjectAction
-{
-    /**
-     * @inheritDoc
-     */
-    protected $className = SpiderEditor::class;
-}
diff --git a/wcfsetup/install/files/lib/data/spider/SpiderEditor.class.php b/wcfsetup/install/files/lib/data/spider/SpiderEditor.class.php
deleted file mode 100644 (file)
index ecbfda3..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php
-
-namespace wcf\data\spider;
-
-use wcf\data\DatabaseObjectEditor;
-
-/**
- * Provides functions to edit spiders.
- *
- * @author  Alexander Ebert
- * @copyright   2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- *
- * @method static Spider      create(array $parameters = [])
- * @method      Spider      getDecoratedObject()
- * @mixin       Spider
- */
-class SpiderEditor extends DatabaseObjectEditor
-{
-    /**
-     * @inheritDoc
-     */
-    protected static $baseClass = Spider::class;
-}
diff --git a/wcfsetup/install/files/lib/data/spider/SpiderList.class.php b/wcfsetup/install/files/lib/data/spider/SpiderList.class.php
deleted file mode 100644 (file)
index f75c5c7..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-
-namespace wcf\data\spider;
-
-use wcf\data\DatabaseObjectList;
-
-/**
- * Represents a list of spiders.
- *
- * @author  Alexander Ebert
- * @copyright   2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- *
- * @method  Spider      current()
- * @method  Spider[]    getObjects()
- * @method  Spider|null getSingleObject()
- * @method  Spider|null search($objectID)
- * @property    Spider[] $objects
- */
-class SpiderList extends DatabaseObjectList
-{
-    /**
-     * @inheritDoc
-     */
-    public $className = Spider::class;
-}
index 214ed7207fe600172d42b6e58d02572be17929ff..babc1a3f70eaa802ccdb79269bfd74621c51a1d8 100644 (file)
@@ -3,11 +3,11 @@
 namespace wcf\data\user\online;
 
 use wcf\data\page\PageCache;
-use wcf\data\spider\Spider;
 use wcf\data\user\UserProfile;
-use wcf\system\cache\builder\SpiderCacheBuilder;
 use wcf\system\event\EventHandler;
 use wcf\system\page\handler\IOnlineLocationPageHandler;
+use wcf\system\spider\Spider;
+use wcf\system\spider\SpiderHandler;
 use wcf\system\WCF;
 use wcf\util\StringUtil;
 use wcf\util\UserAgent;
@@ -24,6 +24,7 @@ use wcf\util\UserUtil;
  * @property-read   int|null $pageObjectID       id of the object the last visited page belongs to
  * @property-read   int|null $parentPageObjectID id of the parent of the object the last visited page belongs to
  * @property-read   string|null $userOnlineMarking  HTML code used to print the formatted name of a user group member
+ * @property-read   string $spiderIdentifier identifier of the spider
  */
 class UserOnline extends UserProfile
 {
@@ -35,9 +36,8 @@ class UserOnline extends UserProfile
 
     /**
      * spider object
-     * @var Spider
      */
-    protected $spider;
+    protected ?Spider $spider;
 
     /**
      * Returns the formatted username.
@@ -152,18 +152,15 @@ class UserOnline extends UserProfile
 
     /**
      * Returns the spider object
-     *
-     * @return  Spider|null
      */
-    public function getSpider()
+    public function getSpider(): ?Spider
     {
-        if (!$this->spiderID) {
+        if (!$this->spiderIdentifier) {
             return null;
         }
 
-        if ($this->spider === null) {
-            $spiderList = SpiderCacheBuilder::getInstance()->getData();
-            $this->spider = $spiderList[$this->spiderID];
+        if (!isset($this->spider)) {
+            $this->spider = SpiderHandler::getInstance()->getSpider($this->spiderIdentifier);
         }
 
         return $this->spider;
index 85453665edf0dbfa5831211693c98a83fca974a4..6f4d0c3509641cab0a557dcb2ec70eab78763e23 100644 (file)
@@ -100,7 +100,7 @@ class UsersOnlineList extends SessionList
     public function readStats()
     {
         $conditionBuilder = clone $this->getConditionBuilder();
-        $conditionBuilder->add('session.spiderID IS NULL');
+        $conditionBuilder->add('session.spiderIdentifier IS NULL');
 
         $sql = "SELECT      user_option_value.userOption" . User::getUserOptionID('canViewOnlineStatus') . " AS canViewOnlineStatus, session.userID
                 FROM        wcf" . WCF_N . "_session session
index ed14555e66fe301f64fb9e32732285b853e73b9a..5ad8fa946c2455c26da476fe608a35f69b3e5b0a 100644 (file)
@@ -198,7 +198,7 @@ class UserPage extends AbstractPage
     public function show()
     {
         // update profile hits
-        if ($this->user->userID != WCF::getUser()->userID && !WCF::getSession()->spiderID && !$this->user->isProtected()) {
+        if ($this->user->userID != WCF::getUser()->userID && !WCF::getSession()->spiderIdentifier && !$this->user->isProtected()) {
             $editor = new UserEditor($this->user->getDecoratedObject());
             $editor->updateCounters(['profileHits' => 1]);
 
index 4962780b49061754c04c1a5ea697321462b47ba0..e172de38445d64f92e236ccc7c91820c240cc5bf 100644 (file)
@@ -91,18 +91,18 @@ class UsersOnlineListPage extends SortablePage
         $this->objectList->checkRecord();
 
         if (!USERS_ONLINE_SHOW_ROBOTS) {
-            $this->objectList->getConditionBuilder()->add('session.spiderID IS NULL');
+            $this->objectList->getConditionBuilder()->add('session.spiderIdentifier IS NULL');
         }
         if (!USERS_ONLINE_SHOW_GUESTS) {
             if (USERS_ONLINE_SHOW_ROBOTS) {
-                $this->objectList->getConditionBuilder()->add('(session.userID IS NOT NULL OR session.spiderID IS NOT NULL)');
+                $this->objectList->getConditionBuilder()->add('(session.userID IS NOT NULL OR session.spiderIdentifier IS NOT NULL)');
             } else {
                 $this->objectList->getConditionBuilder()->add('session.userID IS NOT NULL');
             }
         }
 
         $this->objectList->sqlSelects .= ", CASE WHEN session.userID IS NULL THEN 1 ELSE 0 END AS userIsGuest";
-        $this->objectList->sqlSelects .= ", CASE WHEN session.spiderID IS NOT NULL THEN 1 ELSE 0 END AS userIsRobot";
+        $this->objectList->sqlSelects .= ", CASE WHEN session.spiderIdentifier IS NOT NULL THEN 1 ELSE 0 END AS userIsRobot";
     }
 
     /**
diff --git a/wcfsetup/install/files/lib/system/cache/builder/SpiderCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/SpiderCacheBuilder.class.php
deleted file mode 100644 (file)
index 88183d0..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-
-namespace wcf\system\cache\builder;
-
-use wcf\data\spider\SpiderList;
-
-/**
- * Caches the list of search engine spiders.
- *
- * @author  Marcel Werk
- * @copyright   2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- */
-class SpiderCacheBuilder extends AbstractCacheBuilder
-{
-    /**
-     * @inheritDoc
-     */
-    public function rebuild(array $parameters)
-    {
-        $spiderList = new SpiderList();
-        $spiderList->sqlOrderBy = "spider.spiderID ASC";
-        $spiderList->readObjects();
-
-        if (isset($parameters['fastLookup'])) {
-            $firstCharacter = [];
-            $mapping = [];
-            foreach ($spiderList as $spider) {
-                if (!isset($firstCharacter[$spider->spiderIdentifier[0]])) {
-                    $firstCharacter[$spider->spiderIdentifier[0]] = [];
-                }
-                $firstCharacter[$spider->spiderIdentifier[0]][] = \substr($spider->spiderIdentifier, 1);
-
-                $mapping[$spider->spiderIdentifier] = $spider->spiderID;
-            }
-
-            $regex = '';
-            foreach ($firstCharacter as $char => $spiders) {
-                if ($regex !== '') {
-                    $regex .= '|';
-                }
-                $regex .= \sprintf(
-                    '(?:%s(?:%s))',
-                    \preg_quote($char, '/'),
-                    \implode('|', \array_map(static function ($identifier) {
-                        return \preg_quote($identifier, '/');
-                    }, $spiders))
-                );
-            }
-
-            if ($regex === '') {
-                // This regex will never match anything.
-                $regex = '(?!)';
-            }
-
-            return [
-                'regex' => "/{$regex}/",
-                'mapping' => $mapping,
-            ];
-        }
-
-        return $spiderList->getObjects();
-    }
-}
diff --git a/wcfsetup/install/files/lib/system/cronjob/RefreshSearchRobotsCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/RefreshSearchRobotsCronjob.class.php
deleted file mode 100644 (file)
index 5a4da44..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-<?php
-
-namespace wcf\system\cronjob;
-
-use GuzzleHttp\Psr7\Request;
-use wcf\data\cronjob\Cronjob;
-use wcf\system\cache\builder\SpiderCacheBuilder;
-use wcf\system\io\HttpFactory;
-use wcf\system\WCF;
-use wcf\util\XML;
-
-/**
- * Refreshes list of search robots.
- *
- * @author  Marcel Werk
- * @copyright   2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- */
-class RefreshSearchRobotsCronjob extends AbstractCronjob
-{
-    /**
-     * URL to the spider list.
-     */
-    private const SPIDER_LIST_URL = 'http://assets.woltlab.com/spiderlist/typhoon/list.xml';
-
-    /**
-     * @inheritDoc
-     */
-    public function execute(Cronjob $cronjob)
-    {
-        parent::execute($cronjob);
-
-        $client = HttpFactory::getDefaultClient();
-        $request = new Request('GET', self::SPIDER_LIST_URL);
-        $response = $client->send($request);
-
-        $xml = new XML();
-        $xml->loadXML('list.xml', (string)$response->getBody());
-
-        $xpath = $xml->xpath();
-
-        // fetch spiders
-        $spiders = $xpath->query('/ns:data/ns:spider');
-
-        if (!empty($spiders)) {
-            $existingSpiders = SpiderCacheBuilder::getInstance()->getData();
-            $statementParameters = [];
-
-            /** @var \DOMElement $spider */
-            foreach ($spiders as $spider) {
-                $identifier = \mb_strtolower($spider->getAttribute('ident'));
-                $name = $xpath->query('ns:name', $spider)->item(0);
-                $info = $xpath->query('ns:url', $spider)->item(0);
-
-                $statementParameters[$identifier] = [
-                    'spiderIdentifier' => $identifier,
-                    'spiderName' => $name->nodeValue,
-                    'spiderURL' => $info ? $info->nodeValue : '',
-                ];
-            }
-
-            if (!empty($statementParameters)) {
-                $sql = "INSERT INTO             wcf" . WCF_N . "_spider
-                                                (spiderIdentifier, spiderName, spiderURL)
-                        VALUES                  (?, ?, ?)
-                        ON DUPLICATE KEY UPDATE spiderName = VALUES(spiderName),
-                                                spiderURL = VALUES(spiderURL)";
-                $statement = WCF::getDB()->prepareStatement($sql);
-
-                WCF::getDB()->beginTransaction();
-                foreach ($statementParameters as $parameters) {
-                    $statement->execute([
-                        $parameters['spiderIdentifier'],
-                        $parameters['spiderName'],
-                        $parameters['spiderURL'],
-                    ]);
-                }
-                WCF::getDB()->commitTransaction();
-            }
-
-            // delete obsolete entries
-            $sql = "DELETE FROM wcf" . WCF_N . "_spider WHERE spiderIdentifier = ?";
-            $statement = WCF::getDB()->prepareStatement($sql);
-            foreach ($existingSpiders as $spider) {
-                if (!isset($statementParameters[$spider->spiderIdentifier])) {
-                    $statement->execute([$spider->spiderIdentifier]);
-                }
-            }
-
-            // clear spider cache
-            SpiderCacheBuilder::getInstance()->reset();
-        }
-    }
-}
index 8bd1c7607a2ec376fb068ebe5ab394505344e190..bf6a61dc31fac788259ac3344fc0be44bc615c82 100644 (file)
@@ -7,7 +7,6 @@ use wcf\data\session\Session as LegacySession;
 use wcf\data\session\SessionEditor;
 use wcf\data\user\User;
 use wcf\data\user\UserEditor;
-use wcf\system\cache\builder\SpiderCacheBuilder;
 use wcf\system\cache\builder\UserGroupOptionCacheBuilder;
 use wcf\system\cache\builder\UserGroupPermissionCacheBuilder;
 use wcf\system\database\exception\DatabaseQueryExecutionException;
@@ -18,6 +17,7 @@ use wcf\system\page\PageLocationManager;
 use wcf\system\request\RouteHandler;
 use wcf\system\session\event\PreserveVariablesCollecting;
 use wcf\system\SingletonFactory;
+use wcf\system\spider\SpiderHandler;
 use wcf\system\user\storage\UserStorageHandler;
 use wcf\system\WCF;
 use wcf\system\WCFACP;
@@ -38,7 +38,7 @@ use wcf\util\UserUtil;
  * @property-read   int|null $pageObjectID       id of the object the latest page visited belongs to
  * @property-read   int|null $parentPageID       id of the parent page of latest page visited
  * @property-read   int|null $parentPageObjectID id of the object the parent page of latest page visited belongs to
- * @property-read   int $spiderID       id of the spider the session belongs to
+ * @property-read   int $spiderIdentifier       identifier of the spider
  */
 final class SessionHandler extends SingletonFactory
 {
@@ -135,7 +135,7 @@ final class SessionHandler extends SingletonFactory
                 return $this->sessionID;
             case 'userID':
                 return $this->user->userID;
-            case 'spiderID':
+            case 'spiderIdentifier':
                 if ($this->userID) {
                     return null;
                 }
@@ -144,7 +144,7 @@ final class SessionHandler extends SingletonFactory
                     return null;
                 }
 
-                return $this->legacySession->spiderID;
+                return $this->legacySession->spiderIdentifier;
             case 'pageID':
             case 'pageObjectID':
             case 'parentPageID':
@@ -584,9 +584,9 @@ final class SessionHandler extends SingletonFactory
                 $condition->add('userID = ?', [$row['userID']]);
             } else {
                 $condition->add('userID IS NULL');
-                $condition->add('(sessionID = ? OR spiderID = ?)', [
+                $condition->add('(sessionID = ? OR spiderIdentifier = ?)', [
                     $row['sessionID'],
-                    $this->getSpiderID(UserUtil::getUserAgent()),
+                    $this->getSpiderIdentifier(UserUtil::getUserAgent()),
                 ]);
             }
 
@@ -662,15 +662,15 @@ final class SessionHandler extends SingletonFactory
         if (!$this->isACP) {
             // Try to find an existing spider session. Order by lastActivityTime to maintain a
             // stable selection in case duplicates exist for some reason.
-            $spiderID = $this->getSpiderID(UserUtil::getUserAgent());
-            if ($spiderID) {
+            $spiderIdentifier = $this->getSpiderIdentifier(UserUtil::getUserAgent());
+            if ($spiderIdentifier) {
                 $sql = "SELECT      *
                         FROM        wcf1_session
-                        WHERE       spiderID = ?
+                        WHERE       spiderIdentifier = ?
                                 AND userID IS NULL
                         ORDER BY    lastActivityTime DESC";
                 $statement = WCF::getDB()->prepare($sql);
-                $statement->execute([$spiderID]);
+                $statement->execute([$spiderIdentifier]);
                 $this->legacySession = $statement->fetchSingleObject(LegacySession::class);
             }
 
@@ -682,9 +682,9 @@ final class SessionHandler extends SingletonFactory
 
     private function createLegacySession(): LegacySession
     {
-        $spiderID = null;
+        $spiderIdentifier = null;
         if (!$this->user->userID) {
-            $spiderID = $this->getSpiderID(UserUtil::getUserAgent());
+            $spiderIdentifier = $this->getSpiderIdentifier(UserUtil::getUserAgent());
         }
 
         // save session
@@ -696,7 +696,7 @@ final class SessionHandler extends SingletonFactory
             'lastActivityTime' => TIME_NOW,
             'requestURI' => UserUtil::getRequestURI(),
             'requestMethod' => !empty($_SERVER['REQUEST_METHOD']) ? \substr($_SERVER['REQUEST_METHOD'], 0, 7) : '',
-            'spiderID' => $spiderID,
+            'spiderIdentifier' => $spiderIdentifier,
         ];
 
         return SessionEditor::create($sessionData);
@@ -1291,18 +1291,11 @@ final class SessionHandler extends SingletonFactory
     }
 
     /**
-     * Returns the spider id for given user agent.
+     * Returns the spider identifier for given user agent.
      */
-    private function getSpiderID(string $userAgent): ?int
+    private function getSpiderIdentifier(string $userAgent): ?string
     {
-        $data = SpiderCacheBuilder::getInstance()->getData(['fastLookup' => true]);
-        $userAgent = \strtolower($userAgent);
-
-        if (!\preg_match($data['regex'], $userAgent, $matches)) {
-            return null;
-        }
-
-        return $data['mapping'][$matches[0]];
+        return SpiderHandler::getInstance()->getIdentifier($userAgent);
     }
 
     /**
diff --git a/wcfsetup/install/files/lib/system/spider/Spider.class.php b/wcfsetup/install/files/lib/system/spider/Spider.class.php
new file mode 100644 (file)
index 0000000..091965d
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+namespace wcf\system\spider;
+
+/**
+ * @author      Olaf Braun
+ * @copyright   2001-2024 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ */
+final readonly class Spider
+{
+    public function __construct(
+        public string $identifier,
+        public string $name,
+        public ?string $url
+    ) {
+    }
+}
diff --git a/wcfsetup/install/files/lib/system/spider/SpiderHandler.class.php b/wcfsetup/install/files/lib/system/spider/SpiderHandler.class.php
new file mode 100644 (file)
index 0000000..d077969
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+namespace wcf\system\spider;
+
+use wcf\system\SingletonFactory;
+
+/**
+ * @author      Olaf Braun
+ * @copyright   2001-2024 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ */
+final class SpiderHandler extends SingletonFactory
+{
+    public function getSpider(string $identifier): ?Spider
+    {
+        //TODO
+        return null;
+    }
+
+    public function getIdentifier(string $userAgent): ?string
+    {
+        $userAgent = \strtolower($userAgent);
+        //TODO
+
+        return null;
+    }
+}
index 31a4572eeb00c44993efd7c66ac2486afb3f9bfb..8604045d0620f55f75e56ac7a0f1be6a49fc20a0 100644 (file)
@@ -204,7 +204,7 @@ class VisitTracker extends SingletonFactory
                     VALUES          (?, ?, ?, ?)";
             $statement = WCF::getDB()->prepare($sql);
             $statement->execute([$this->getObjectTypeID($objectType), $objectID, WCF::getUser()->userID, $time]);
-        } elseif (WCF::getSession()->spiderID === null) {
+        } elseif (WCF::getSession()->spiderIdentifier === null) {
             WCF::getSession()->register(
                 'trackedUserVisit_' . $this->getObjectTypeID($objectType) . '_' . $objectID,
                 $time
@@ -238,7 +238,7 @@ class VisitTracker extends SingletonFactory
 
             // reset storage
             UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'trackedUserVisits');
-        } elseif (WCF::getSession()->spiderID === null) {
+        } elseif (WCF::getSession()->spiderIdentifier === null) {
             $this->getVisitTime($objectType);
             $this->userVisits[$this->getObjectTypeID($objectType)] = $time;
             WCF::getSession()->register('trackedUserVisits', $this->userVisits);
index 9dfa6c81fbae36f509fad557318f949cf2420ed2..e4223eed2960b38375f5de593e36b1abff8fc450 100644 (file)
@@ -87,7 +87,7 @@ final class HeaderUtil
         @\header('Content-Type: text/html; charset=UTF-8');
 
         // send no cache headers
-        if (!WCF::getSession()->spiderID) {
+        if (!WCF::getSession()->spiderIdentifier) {
             self::sendNoCacheHeaders();
         }
 
index 59aecbe0ebcfae15586accb48d44dbfe869b9f51..57bdb0235689ce191da3d06b9972fafb01dbb871 100644 (file)
@@ -1271,8 +1271,8 @@ CREATE TABLE wcf1_session (
        pageObjectID INT(10),
        parentPageID INT(10),
        parentPageObjectID INT(10),
-       spiderID INT(10),
-       KEY packageID (lastActivityTime, spiderID),
+       spiderIdentifier VARCHAR(191) DEFAULT NULL,
+       KEY packageID (lastActivityTime, spiderIdentifier),
        KEY pageID (pageID, pageObjectID),
        KEY parentPageID (parentPageID, parentPageObjectID),
        UNIQUE KEY uniqueUserID (userID)
@@ -1292,15 +1292,6 @@ CREATE TABLE wcf1_smiley (
        UNIQUE KEY smileyCode (smileyCode)
 );
 
-DROP TABLE IF EXISTS wcf1_spider;
-CREATE TABLE wcf1_spider (
-       spiderID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
-       spiderIdentifier VARCHAR(191) DEFAULT '',
-       spiderName VARCHAR(255) DEFAULT '',
-       spiderURL VARCHAR(255) DEFAULT '',
-       UNIQUE KEY spiderIdentifier (spiderIdentifier)
-);
-
 DROP TABLE IF EXISTS wcf1_stat_daily;
 CREATE TABLE wcf1_stat_daily (
        statID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -2127,7 +2118,6 @@ ALTER TABLE wcf1_search ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) O
 /* SQL_PARSER_OFFSET */
 
 ALTER TABLE wcf1_session ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE;
-ALTER TABLE wcf1_session ADD FOREIGN KEY (spiderID) REFERENCES wcf1_spider (spiderID) ON DELETE CASCADE;
 ALTER TABLE wcf1_session ADD FOREIGN KEY (pageID) REFERENCES wcf1_page (pageID) ON DELETE SET NULL;
 ALTER TABLE wcf1_session ADD FOREIGN KEY (parentPageID) REFERENCES wcf1_page (pageID) ON DELETE SET NULL;