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