Commit | Line | Data |
---|---|---|
11ade432 | 1 | <?php |
a9229942 | 2 | |
11ade432 | 3 | namespace wcf\system\package; |
a9229942 | 4 | |
04727c8b | 5 | use wcf\data\package\Package; |
11ade432 | 6 | use wcf\system\database\util\PreparedStatementConditionBuilder; |
04727c8b | 7 | use wcf\system\exception\SystemException; |
11ade432 AE |
8 | use wcf\system\WCF; |
9 | ||
10 | /** | |
a17de04e | 11 | * File handler implementation for the installation of regular files. |
a9229942 TD |
12 | * |
13 | * @author Matthias Schmidt, Marcel Werk | |
14 | * @copyright 2001-2019 WoltLab GmbH | |
15 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
16 | * @package WoltLabSuite\Core\System\Package | |
11ade432 | 17 | */ |
a9229942 TD |
18 | class FilesFileHandler extends PackageInstallationFileHandler |
19 | { | |
20 | /** | |
21 | * @inheritDoc | |
22 | */ | |
23 | public function checkFiles(array $files) | |
24 | { | |
25 | if ($this->packageInstallation->getPackage()->package != 'com.woltlab.wcf') { | |
26 | if (!empty($files)) { | |
27 | // get registered files of other packages for the | |
28 | // same application | |
29 | $conditions = new PreparedStatementConditionBuilder(); | |
30 | $conditions->add('packageID <> ?', [$this->packageInstallation->getPackageID()]); | |
31 | $conditions->add('filename IN (?)', [$files]); | |
32 | $conditions->add('application = ?', [$this->application]); | |
33 | ||
34 | $sql = "SELECT filename, packageID | |
35 | FROM wcf" . WCF_N . "_package_installation_file_log | |
36 | " . $conditions; | |
37 | $statement = WCF::getDB()->prepareStatement($sql); | |
38 | $statement->execute($conditions->getParameters()); | |
39 | $lockedFiles = $statement->fetchMap('filename', 'packageID'); | |
40 | ||
41 | // check delivered files | |
42 | if (!empty($lockedFiles)) { | |
13b11e4c | 43 | foreach ($files as $file) { |
a9229942 TD |
44 | if (isset($lockedFiles[$file])) { |
45 | $owningPackage = new Package($lockedFiles[$file]); | |
46 | ||
47 | throw new SystemException("A package can't overwrite files from other packages. Only an update from the package which owns the file can do that. (Package '" . $this->packageInstallation->getPackage()->package . "' tries to overwrite file '" . $file . "', which is owned by package '" . $owningPackage->package . "')"); | |
48 | } | |
49 | } | |
50 | } | |
51 | } | |
52 | } | |
53 | } | |
54 | ||
55 | /** | |
56 | * @inheritDoc | |
57 | */ | |
58 | public function logFiles(array $files) | |
59 | { | |
60 | if (empty($files)) { | |
61 | return; | |
62 | } | |
63 | ||
64 | $sql = "INSERT IGNORE INTO wcf" . WCF_N . "_package_installation_file_log | |
65 | (packageID, filename, application) | |
66 | VALUES (?, ?, ?)"; | |
67 | $statement = WCF::getDB()->prepareStatement($sql); | |
68 | ||
69 | WCF::getDB()->beginTransaction(); | |
70 | foreach ($files as $file) { | |
71 | $statement->execute([ | |
72 | $this->packageInstallation->getPackageID(), | |
73 | $file, | |
74 | $this->application, | |
75 | ]); | |
76 | } | |
77 | WCF::getDB()->commitTransaction(); | |
78 | } | |
11ade432 | 79 | } |