Skip to content

Commit ca5d81b

Browse files
committed
Add oldFiles property for managing file updates
Added a property to track old installed files for updates. This allows the parseFiles() method to automatically remove deleted files. Same code is already used in plugin and component adapter.
1 parent 29709ef commit ca5d81b

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

libraries/src/Installer/Adapter/ModuleAdapter.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ class ModuleAdapter extends InstallerAdapter
4646
*/
4747
protected $scriptElement = null;
4848

49+
/**
50+
* The list of current files that are installed and is read
51+
* from the manifest on disk in the update area to handle doing a diff
52+
* and deleting files that are in the old files list and not in the new
53+
* files list.
54+
*
55+
* @var array
56+
* @since 5.4
57+
* */
58+
protected $oldFiles = null;
59+
4960
/**
5061
* Method to check if the extension is already present in the database
5162
*
@@ -89,7 +100,7 @@ protected function checkExistingExtension()
89100
protected function copyBaseFiles()
90101
{
91102
// Copy all necessary files
92-
if ($this->parent->parseFiles($this->getManifest()->files, -1) === false) {
103+
if ($this->parent->parseFiles($this->getManifest()->files, -1, $this->oldFiles) === false) {
93104
throw new \RuntimeException(Text::_('JLIB_INSTALLER_ABORT_MOD_COPY_FILES'));
94105
}
95106

@@ -527,6 +538,29 @@ protected function setupUninstall()
527538
$this->loadLanguage(($this->extension->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/modules/' . $element);
528539
}
529540

541+
/**
542+
* Method to setup the update routine for the adapter
543+
*
544+
* @return void
545+
*
546+
* @since 5.4
547+
*/
548+
protected function setupUpdates()
549+
{
550+
// Create a new installer because findManifest sets stuff; side effects!
551+
$tmpInstaller = new Installer();
552+
$tmpInstaller->setDatabase($this->getDatabase());
553+
554+
// Look in the extension root
555+
$tmpInstaller->setPath('source', $this->parent->getPath('extension_root'));
556+
557+
if ($tmpInstaller->findManifest())
558+
{
559+
$old_manifest = $tmpInstaller->getManifest();
560+
$this->oldFiles = $old_manifest->files;
561+
}
562+
}
563+
530564
/**
531565
* Method to store the extension to the database
532566
*

0 commit comments

Comments
 (0)