3 namespace wcf\system\package
;
5 use wcf\data\application\Application
;
6 use wcf\data\package\Package
;
7 use wcf\system\database\util\PreparedStatementConditionBuilder
;
8 use wcf\system\exception\SystemException
;
12 * File handler implementation for the installation of regular files.
14 * @author Matthias Schmidt, Marcel Werk
15 * @copyright 2001-2019 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 class FilesFileHandler
extends PackageInstallationFileHandler
23 public function checkFiles(array $files)
25 if ($this->packageInstallation
->getPackage()->package
!= 'com.woltlab.wcf') {
27 // get registered files of other packages for the
29 $conditions = new PreparedStatementConditionBuilder();
30 $conditions->add('packageID <> ?', [$this->packageInstallation
->getPackageID()]);
31 $conditions->add('filename IN (?)', [$files]);
32 $conditions->add('application = ?', [$this->application
]);
34 $sql = "SELECT filename, packageID
35 FROM wcf1_package_installation_file_log
37 $statement = WCF
::getDB()->prepare($sql);
38 $statement->execute($conditions->getParameters());
39 $lockedFiles = $statement->fetchMap('filename', 'packageID');
41 // check delivered files
42 if (!empty($lockedFiles)) {
43 foreach ($files as $file) {
44 if (isset($lockedFiles[$file])) {
45 $owningPackage = new Package($lockedFiles[$file]);
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
. "')");
58 public function logFiles(array $files)
64 $baseDirectory = Application
::getDirectory($this->application
);
66 $sql = "INSERT INTO wcf1_package_installation_file_log
67 (packageID, filename, application, sha256, lastUpdated)
68 VALUES (?, ?, ?, ?, ?)
69 ON DUPLICATE KEY UPDATE sha256 = VALUES(sha256),
70 lastUpdated = VALUES(lastUpdated)";
71 $statement = WCF
::getDB()->prepare($sql);
73 WCF
::getDB()->beginTransaction();
74 foreach ($files as $file) {
76 $this->packageInstallation
->getPackageID(),
79 \
hash_file('sha256', $baseDirectory . $file, true),
83 WCF
::getDB()->commitTransaction();