│ │ └── Controller
│ │ └── Person.js
│ └── lib
-│ └── data
-│ └── person
-│ ├── Person.class.php
-│ └── information
-│ ├── PersonInformation.class.php
-│ ├── PersonInformationAction.class.php
-│ ├── PersonInformationEditor.class.php
-│ └── PersonInformationList.class.php
+│ ├── data
+│ │ └── person
+│ │ ├── Person.class.php
+│ │ └── information
+│ │ ├── PersonInformation.class.php
+│ │ ├── PersonInformationAction.class.php
+│ │ ├── PersonInformationEditor.class.php
+│ │ └── PersonInformationList.class.php
+│ └── system
+│ └── worker
+│ └── PersonRebuildDataWorker.class.php
├── language
│ ├── de.xml
│ └── en.xml
After editing a piece of information, we do not reload the page but dynamically update the text of the information in the TypeScript code so that we return the updated rendered information text and id of the edited pieced of information in `submitAddDialog()`.
+## Rebuild Data Worker
+
+To ensure the integrity of the person data, `PersonRebuildDataWorker` updates the `informationCount` counter:
+
+{jinja{ codebox(
+title="files/lib/system/worker/PersonRebuildDataWorker.class.php",
+language="php",
+filepath="tutorial/tutorial-series/part-5/files/lib/system/worker/PersonRebuildDataWorker.class.php"
+) }}
+
+
## Username and IP Address Event Listeners
As we store the name of the user who create a new piece of information and store their IP address, we have to add event listeners to properly handle the following scenarios:
--- /dev/null
+<?php
+
+namespace wcf\system\worker;
+
+use wcf\data\person\PersonList;
+use wcf\system\WCF;
+
+/**
+ * Worker implementation for updating people.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Worker
+ *
+ * @method PersonList getObjectList()
+ */
+class PersonRebuildDataWorker extends AbstractRebuildDataWorker
+{
+ /**
+ * @inheritDoc
+ */
+ protected $limit = 500;
+
+ /**
+ * @inheritDoc
+ */
+ protected $objectListClassName = PersonList::class;
+
+ /**
+ * @inheritDoc
+ */
+ protected function initObjectList()
+ {
+ parent::initObjectList();
+
+ $this->objectList->sqlOrderBy = 'person.personID';
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function execute()
+ {
+ parent::execute();
+
+ if (!\count($this->objectList)) {
+ return;
+ }
+
+ $sql = "UPDATE wcf" . WCF_N . "_person person
+ SET informationCount = (
+ SELECT COUNT(*)
+ FROM wcf" . WCF_N . "_person_information person_information
+ WHERE person_information.personID = person.personID
+ )
+ WHERE person.personID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+
+ WCF::getDB()->beginTransaction();
+ foreach ($this->getObjectList() as $person) {
+ $statement->execute([$person->personID]);
+ }
+ WCF::getDB()->commitTransaction();
+ }
+}
<name>com.woltlab.wcf.people.information</name>
<definitionname>com.woltlab.wcf.message</definitionname>
</type>
+ <type>
+ <name>com.woltlab.wcf.people.person</name>
+ <definitionname>com.woltlab.wcf.rebuildData</definitionname>
+ <classname>wcf\system\worker\PersonRebuildDataWorker</classname>
+ </type>
</import>
</data>