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