Apply PSR-12 code style (#3886)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / importer / AbstractWatchedObjectImporter.class.php
1 <?php
2
3 namespace wcf\system\importer;
4
5 use wcf\data\user\object\watch\UserObjectWatch;
6 use wcf\data\user\object\watch\UserObjectWatchEditor;
7 use wcf\system\database\DatabaseException;
8
9 /**
10 * Imports watched objects.
11 *
12 * @author Marcel Werk
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\Importer
16 */
17 class AbstractWatchedObjectImporter extends AbstractImporter
18 {
19 /**
20 * @inheritDoc
21 */
22 protected $className = UserObjectWatch::class;
23
24 /**
25 * object type id for watched objects
26 * @var int
27 */
28 protected $objectTypeID = 0;
29
30 /**
31 * @inheritDoc
32 */
33 public function import($oldID, array $data, array $additionalData = [])
34 {
35 $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
36 if (!$data['userID']) {
37 return 0;
38 }
39
40 try {
41 $watch = UserObjectWatchEditor::create(\array_merge($data, ['objectTypeID' => $this->objectTypeID]));
42
43 return $watch->watchID;
44 } catch (DatabaseException $e) {
45 // 23000 = INTEGRITY CONSTRAINT VIOLATION a.k.a. duplicate key
46 if ($e->getCode() != 23000) {
47 throw $e;
48 }
49 }
50
51 return 0;
52 }
53 }