Skip to content

Commit a8a4b48

Browse files
committed
Merge pull request joomla#9 from mahagr/installAbstract
Give either extension or manifest parameter for all InstallerAdapters
2 parents b07f347 + 119097b commit a8a4b48

File tree

3 files changed

+53
-40
lines changed

3 files changed

+53
-40
lines changed

libraries/cms/installer/adapter.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ abstract class JInstallerAdapter extends JAdapterInstance
2828
* */
2929
protected $element = null;
3030

31+
/**
32+
* Extension object.
33+
*
34+
* @var JTableExtension
35+
* @since 3.1
36+
* */
37+
protected $extension = null;
38+
3139
/**
3240
* Messages rendered by custom scripts
3341
*
@@ -92,7 +100,7 @@ public function __construct($parent, $db, $options = array())
92100
parent::__construct($parent, $db, $options);
93101

94102
// Set the manifest object
95-
$this->manifest = $this->parent->getManifest();
103+
$this->manifest = $this->getManifest();
96104

97105
// Set name and element
98106
$this->name = $this->getName();
@@ -226,6 +234,24 @@ protected function extensionExists($extension, $type, $clientId = null)
226234
return $id > 0;
227235
}
228236

237+
/**
238+
* Get the manifest object.
239+
*
240+
* @return object Manifest object
241+
*
242+
* @since 3.1
243+
*/
244+
public function getManifest()
245+
{
246+
if (!$this->manifest) {
247+
// We are trying to find manifest for the installed extension.
248+
// TODO: handle locally in every adapter (see uninstall to get some hints).
249+
$this->manifest = $this->parent->getManifest();
250+
}
251+
252+
return $this->manifest;
253+
}
254+
229255
/**
230256
* Get the filtered component name from the manifest
231257
*

libraries/cms/installer/adapter/library.php

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function loadLanguage($path = null)
5353

5454
if (!$source)
5555
{
56-
$this->parent->setPath('source', JPATH_PLATFORM . '/' . $this->parent->extension->element);
56+
$this->parent->setPath('source', JPATH_PLATFORM . '/' . $this->element);
5757
}
5858

5959
$extension = 'lib_' . $this->element;
@@ -80,7 +80,7 @@ public function install()
8080
* ---------------------------------------------------------------------------------------------
8181
*/
8282

83-
$extension_id = $this->extensionExists($this->element, 'library');
83+
$extension_id = JTable::getInstance('extension')->find(array('element' => $this->element, 'type' => 'library'));
8484
if ($extension_id)
8585
{
8686
// Already installed, can we upgrade?
@@ -192,34 +192,6 @@ public function install()
192192
return $row->extension_id;
193193
}
194194

195-
/**
196-
* Custom update method
197-
*
198-
* @return boolean True on success
199-
*
200-
* @since 3.1
201-
*/
202-
public function update()
203-
{
204-
// Since this is just files, an update removes old files
205-
206-
/*
207-
* ---------------------------------------------------------------------------------------------
208-
* Manifest Document Setup Section
209-
* ---------------------------------------------------------------------------------------------
210-
*/
211-
212-
$extension_id = JTable::getInstance('extension')->find(array('element' => $this->element, 'type' => 'library'));
213-
if ($extension_id)
214-
{
215-
// Already installed, which would make sense
216-
$installer = new JInstaller; // We don't want to compromise this instance!
217-
$installer->uninstall('library', $extension_id);
218-
}
219-
// Now create the new files
220-
return $this->install();
221-
}
222-
223195
/**
224196
* Custom uninstall method
225197
*

libraries/cms/installer/installer.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,11 @@ public function discover_install($eid = null)
500500
}
501501

502502
// Lazy load the adapter
503+
$adapter = null;
503504
if (!isset($this->_adapters[$this->extension->type]) || !is_object($this->_adapters[$this->extension->type]))
504505
{
505-
if (!$this->setAdapter($this->extension->type))
506+
$params = array('extension' => $this->extension);
507+
if (!$this->setAdapter($this->extension->type, $adapter, $params))
506508
{
507509
return false;
508510
}
@@ -691,17 +693,22 @@ public function update($path = null)
691693
* Package uninstallation method
692694
*
693695
* @param string $type Package type
694-
* @param mixed $identifier Package identifier for adapter
696+
* @param mixed $eid Package identifier for adapter
695697
*
696698
* @return boolean True if successful
697699
*
698700
* @since 3.1
699701
*/
700-
public function uninstall($type, $identifier)
702+
public function uninstall($type, $eid)
701703
{
704+
$this->extension = JTable::getInstance('extension');
705+
$this->extension->load(array('type'=>$type, 'extension_id'=>$eid));
706+
707+
$adapter = null;
702708
if (!isset($this->_adapters[$type]) || !is_object($this->_adapters[$type]))
703709
{
704-
if (!$this->setAdapter($type))
710+
$params = array('extension' => $this->extension);
711+
if (!$this->setAdapter($type, $adapter, $params))
705712
{
706713
// We failed to get the right adapter
707714
return false;
@@ -714,12 +721,12 @@ public function uninstall($type, $identifier)
714721
// Fire the onExtensionBeforeUninstall event.
715722
JPluginHelper::importPlugin('extension');
716723
$dispatcher = JEventDispatcher::getInstance();
717-
$dispatcher->trigger('onExtensionBeforeUninstall', array('eid' => $identifier));
724+
$dispatcher->trigger('onExtensionBeforeUninstall', array('eid' => $eid));
718725

719726
// Run the uninstall.
720727
$errorMsg = '';
721728
try {
722-
$result = (bool) $this->_adapters[$type]->uninstall($identifier);
729+
$result = (bool) $this->_adapters[$type]->uninstall($eid);
723730
}
724731
catch (Exception $e)
725732
{
@@ -735,7 +742,7 @@ public function uninstall($type, $identifier)
735742
'onExtensionAfterUninstall',
736743
array(
737744
'installer' => clone $this,
738-
'eid' => $identifier,
745+
'eid' => $eid,
739746
'result' => $result
740747
)
741748
);
@@ -776,9 +783,11 @@ public function refreshManifestCache($eid)
776783
}
777784

778785
// Lazy load the adapter
786+
$adapter = null;
779787
if (!isset($this->_adapters[$this->extension->type]) || !is_object($this->_adapters[$this->extension->type]))
780788
{
781-
if (!$this->setAdapter($this->extension->type))
789+
$params = array('extension' => $this->extension);
790+
if (!$this->setAdapter($this->extension->type, $adapter, $params))
782791
{
783792
return false;
784793
}
@@ -839,9 +848,11 @@ public function setupInstall()
839848
$type = (string) $this->manifest->attributes()->type;
840849

841850
// Lazy load the adapter
851+
$adapter = null;
842852
if (!isset($this->_adapters[$type]) || !is_object($this->_adapters[$type]))
843853
{
844-
if (!$this->setAdapter($type))
854+
$params = array('manifest' => $this->manifest);
855+
if (!$this->setAdapter($type, $adapter, $params))
845856
{
846857
return false;
847858
}
@@ -1851,6 +1862,10 @@ public function copyManifest($cid = 1)
18511862
*/
18521863
public function findManifest()
18531864
{
1865+
if (!$this->getPath('source')) {
1866+
return false;
1867+
}
1868+
18541869
// Get an array of all the XML files from the installation directory
18551870
$xmlfiles = JFolder::files($this->getPath('source'), '.xml$', 1, true);
18561871

0 commit comments

Comments
 (0)