Back to Installer class

Method findManifest

public bool
findManifest
()
Tries to find the package manifest file
Returns
  • bool True on success, False on error
Since
  • 3.1
Class: Installer
Project: Joomla

Method findManifest - Source code

/**
 * Tries to find the package manifest file
 *
 * @return  boolean  True on success, False on error
 *
 * @since   3.1
 */
public function findManifest()
{
    // Do nothing if folder does not exist for some reason
    if (!Folder::exists($this->getPath('source'))) {
        return false;
    }
    // Main folder manifests (higher priority)
    $parentXmlfiles = Folder::files($this->getPath('source'), '.xml$', false, true);
    // Search for children manifests (lower priority)
    $allXmlFiles = Folder::files($this->getPath('source'), '.xml$', 1, true);
    // Create an unique array of files ordered by priority
    $xmlfiles = array_unique(array_merge($parentXmlfiles, $allXmlFiles));
    // If at least one XML file exists
    if (!empty($xmlfiles)) {
        foreach ($xmlfiles as $file) {
            // Is it a valid Joomla installation manifest file?
            $manifest = $this->isManifest($file);
            if ($manifest !== null) {
                // If the root method attribute is set to upgrade, allow file overwrite
                if ((string) $manifest->attributes()->method === 'upgrade') {
                    $this->upgrade = true;
                    $this->overwrite = true;
                }
                // If the overwrite option is set, allow file overwriting
                if ((string) $manifest->attributes()->overwrite === 'true') {
                    $this->overwrite = true;
                }
                // Set the manifest object and path
                $this->manifest = $manifest;
                $this->setPath('manifest', $file);
                // Set the installation source path to that of the manifest file
                $this->setPath('source', \dirname($file));
                return true;
            }
        }
        // None of the XML files found were valid install files
        Log::add(Text::_('JLIB_INSTALLER_ERROR_NOTFINDJOOMLAXMLSETUPFILE'), Log::WARNING, 'jerror');
        return false;
    } else {
        // No XML files were found in the install folder
        Log::add(Text::_('JLIB_INSTALLER_ERROR_NOTFINDXMLSETUPFILE'), Log::WARNING, 'jerror');
        return false;
    }
}