Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
368cf30d
Commit
368cf30d
authored
Mar 10, 2012
by
webchick
Browse files
Issue
#1471376
by amateescu: Convert updater.inc to
PSR-0
.
parent
59e142d1
Changes
12
Hide whitespace changes
Inline
Side-by-side
core/includes/common.inc
View file @
368cf30d
...
...
@@ -7797,9 +7797,10 @@ function archiver_get_archiver($file) {
* file system, for example to update modules that have newer releases, or to
* install a new theme.
*
* @return
* @return
array
* The Drupal Updater class registry.
*
* @see Drupal\Core\Updater\Updater
* @see hook_updater_info()
* @see hook_updater_info_alter()
*/
...
...
core/
modules/system/system.updater.inc
→
core/
lib/Drupal/Core/Updater/Module.php
View file @
368cf30d
...
...
@@ -2,17 +2,19 @@
/**
* @file
* Subclasses of the Updater class to update Drupal core knows how to update.
* At this time, only modules and themes are supported.
* Definition of Drupal\Core\Updater\Module.
*/
namespace
Drupal\Core\Updater
;
/**
* Class for updating modules using FileTransfer classes via authorize.php.
* Defines a class for updating modules using
* Drupal\Core\FileTransfer\FileTransfer classes via authorize.php.
*/
class
Module
Updater
extends
Updater
implements
Drupal
UpdaterInterface
{
class
Module
extends
Updater
implements
UpdaterInterface
{
/**
* Return the directory where a module should be installed.
* Return
s
the directory where a module should be installed.
*
* If the module is already installed, drupal_get_path() will return
* a valid path and we should install it there (although we need to use an
...
...
@@ -22,6 +24,9 @@ class ModuleUpdater extends Updater implements DrupalUpdaterInterface {
* there's no way that can conflict on a multi-site installation, since
* the Update manager won't let you install a new module if it's already
* found on your system, and if there was a copy in sites/all, we'd see it.
*
* @return string
* A directory path.
*/
public
function
getInstallDirectory
()
{
if
(
$relative_path
=
drupal_get_path
(
'module'
,
$this
->
name
))
{
...
...
@@ -33,10 +38,16 @@ public function getInstallDirectory() {
return
DRUPAL_ROOT
.
'/'
.
$relative_path
;
}
/**
* Implements Drupal\Core\Updater\UpdaterInterface::isInstalled().
*/
public
function
isInstalled
()
{
return
(
bool
)
drupal_get_path
(
'module'
,
$this
->
name
);
}
/**
* Implements Drupal\Core\Updater\UpdaterInterface::canUpdateDirectory().
*/
public
static
function
canUpdateDirectory
(
$directory
)
{
if
(
file_scan_directory
(
$directory
,
'/.*\.module$/'
))
{
return
TRUE
;
...
...
@@ -44,28 +55,37 @@ public static function canUpdateDirectory($directory) {
return
FALSE
;
}
/**
* Determines whether this class can update the specified project.
*
* @param string $project_name
* The project to check.
*
* @return bool
*/
public
static
function
canUpdate
(
$project_name
)
{
return
(
bool
)
drupal_get_path
(
'module'
,
$project_name
);
}
/**
* Return available database schema updates one a new version is installed.
* Returns available database schema updates once a new version is installed.
*
* @return array
*/
public
function
getSchemaUpdates
()
{
require_once
DRUPAL_ROOT
.
'/core/includes/install.inc'
;
require_once
DRUPAL_ROOT
.
'/core/includes/update.inc'
;
if
(
_update_get_project_type
(
$project
)
!=
'module'
)
{
if
(
!
self
::
canUpdate
(
$this
->
name
)
)
{
return
array
();
}
module_load_include
(
'install'
,
$
project
);
module_load_include
(
'install'
,
$
this
->
name
);
if
(
!
$updates
=
drupal_get_schema_versions
(
$
project
))
{
if
(
!
$updates
=
drupal_get_schema_versions
(
$
this
->
name
))
{
return
array
();
}
$updates_to_run
=
array
();
$modules_with_updates
=
update_get_update_list
();
if
(
$updates
=
$modules_with_updates
[
$
project
])
{
if
(
$updates
=
$modules_with_updates
[
$
this
->
name
])
{
if
(
$updates
[
'start'
])
{
return
$updates
[
'pending'
];
}
...
...
@@ -73,6 +93,9 @@ public function getSchemaUpdates() {
return
array
();
}
/**
* Overrides Drupal\Core\Updater\Updater::postInstallTasks().
*/
public
function
postInstallTasks
()
{
return
array
(
l
(
t
(
'Enable newly added modules'
),
'admin/modules'
),
...
...
@@ -80,67 +103,11 @@ public function postInstallTasks() {
);
}
/**
* Overrides Drupal\Core\Updater\Updater::postUpdateTasks().
*/
public
function
postUpdateTasks
()
{
// We don't want to check for DB updates here, we do that once for all
// updated modules on the landing page.
}
}
/**
* Class for updating themes using FileTransfer classes via authorize.php.
*/
class
ThemeUpdater
extends
Updater
implements
DrupalUpdaterInterface
{
/**
* Return the directory where a theme should be installed.
*
* If the theme is already installed, drupal_get_path() will return
* a valid path and we should install it there (although we need to use an
* absolute path, so we prepend DRUPAL_ROOT). If we're installing a new
* theme, we always want it to go into sites/all/themes, since that's
* where all the documentation recommends users install their themes, and
* there's no way that can conflict on a multi-site installation, since
* the Update manager won't let you install a new theme if it's already
* found on your system, and if there was a copy in sites/all, we'd see it.
*/
public
function
getInstallDirectory
()
{
if
(
$relative_path
=
drupal_get_path
(
'theme'
,
$this
->
name
))
{
$relative_path
=
dirname
(
$relative_path
);
}
else
{
$relative_path
=
'sites/all/themes'
;
}
return
DRUPAL_ROOT
.
'/'
.
$relative_path
;
}
public
function
isInstalled
()
{
return
(
bool
)
drupal_get_path
(
'theme'
,
$this
->
name
);
}
static
function
canUpdateDirectory
(
$directory
)
{
// This is a lousy test, but don't know how else to confirm it is a theme.
if
(
file_scan_directory
(
$directory
,
'/.*\.module$/'
))
{
return
FALSE
;
}
return
TRUE
;
}
public
static
function
canUpdate
(
$project_name
)
{
return
(
bool
)
drupal_get_path
(
'theme'
,
$project_name
);
}
public
function
postInstall
()
{
// Update the system table.
clearstatcache
();
system_rebuild_theme_data
();
}
public
function
postInstallTasks
()
{
return
array
(
l
(
t
(
'Enable newly added themes'
),
'admin/appearance'
),
l
(
t
(
'Administration pages'
),
'admin'
),
);
}
}
core/lib/Drupal/Core/Updater/Theme.php
0 → 100644
View file @
368cf30d
<?php
/**
* @file
* Definition of Drupal\Core\Updater\Theme.
*/
namespace
Drupal\Core\Updater
;
/**
* Defines a class for updating themes using
* Drupal\Core\FileTransfer\FileTransfer classes via authorize.php.
*/
class
Theme
extends
Updater
implements
UpdaterInterface
{
/**
* Returns the directory where a theme should be installed.
*
* If the theme is already installed, drupal_get_path() will return
* a valid path and we should install it there (although we need to use an
* absolute path, so we prepend DRUPAL_ROOT). If we're installing a new
* theme, we always want it to go into sites/all/themes, since that's
* where all the documentation recommends users install their themes, and
* there's no way that can conflict on a multi-site installation, since
* the Update manager won't let you install a new theme if it's already
* found on your system, and if there was a copy in sites/all, we'd see it.
*
* @return string
* A directory path.
*/
public
function
getInstallDirectory
()
{
if
(
$relative_path
=
drupal_get_path
(
'theme'
,
$this
->
name
))
{
$relative_path
=
dirname
(
$relative_path
);
}
else
{
$relative_path
=
'sites/all/themes'
;
}
return
DRUPAL_ROOT
.
'/'
.
$relative_path
;
}
/**
* Implements Drupal\Core\Updater\UpdaterInterface::isInstalled().
*/
public
function
isInstalled
()
{
return
(
bool
)
drupal_get_path
(
'theme'
,
$this
->
name
);
}
/**
* Implements Drupal\Core\Updater\UpdaterInterface::canUpdateDirectory().
*/
static
function
canUpdateDirectory
(
$directory
)
{
// This is a lousy test, but don't know how else to confirm it is a theme.
if
(
file_scan_directory
(
$directory
,
'/.*\.module$/'
))
{
return
FALSE
;
}
return
TRUE
;
}
/**
* Determines whether this class can update the specified project.
*
* @param string $project_name
* The project to check.
*
* @return bool
*/
public
static
function
canUpdate
(
$project_name
)
{
return
(
bool
)
drupal_get_path
(
'theme'
,
$project_name
);
}
/**
* Overrides Drupal\Core\Updater\Updater::postInstall().
*/
public
function
postInstall
()
{
// Update the system table.
clearstatcache
();
system_rebuild_theme_data
();
}
/**
* Overrides Drupal\Core\Updater\Updater::postInstallTasks().
*/
public
function
postInstallTasks
()
{
return
array
(
l
(
t
(
'Enable newly added themes'
),
'admin/appearance'
),
l
(
t
(
'Administration pages'
),
'admin'
),
);
}
}
core/
includes/u
pdater.
inc
→
core/
lib/Drupal/Core/Updater/U
pdater.
php
View file @
368cf30d
...
...
@@ -2,78 +2,29 @@
/**
* @file
* Classes used for updating various files in the Drupal webroot. These
* classes use a FileTransfer object to actually perform the operations.
* Normally, the FileTransfer is provided when the site owner is redirected to
* authorize.php as part of a multistep process.
* Definition of Drupal\Core\Updater\Updater.
*/
namespace
Drupal\Core\Updater
;
/**
* Interface for a class which can update a Drupal project.
*
* An Updater currently serves the following purposes:
* - It can take a given directory, and determine if it can operate on it.
* - It can move the contents of that directory into the appropriate place
* on the system using FileTransfer classes.
* - It can return a list of "next steps" after an update or install.
* - In the future, it will most likely perform some of those steps as well.
* Defines the base class for Updaters used in Drupal.
*/
interface
DrupalUpdaterInterface
{
/**
* Checks if the project is installed.
*
* @return bool
*/
public
function
isInstalled
();
class
Updater
{
/**
*
Returns the system name of the project
.
*
Directory to install from
.
*
* @param string $directory
* A directory containing a project.
*/
public
static
function
getProjectName
(
$directory
);
/**
* @return string
* An absolute path to the default install location.
* @var string
*/
public
function
getInstallDirectory
()
;
public
$source
;
/**
*
Determine if the Updater can handle the project provided in $directory
.
*
Constructs a new updater
.
*
* @todo: Provide something more rational here, like a project spec file.
*
* @param string $directory
*
* @return bool
* TRUE if the project is installed, FALSE if not.
*/
public
static
function
canUpdateDirectory
(
$directory
);
/**
* Actions to run after an install has occurred.
*/
public
function
postInstall
();
/**
* Actions to run after an update has occurred.
*/
public
function
postUpdate
();
}
/**
* Base class for Updaters used in Drupal.
*/
class
Updater
{
/**
* @var string $source Directory to install from.
* @param string $source
* Directory to install from.
*/
public
$source
;
public
function
__construct
(
$source
)
{
$this
->
source
=
$source
;
$this
->
name
=
self
::
getProjectName
(
$source
);
...
...
@@ -81,7 +32,7 @@ public function __construct($source) {
}
/**
* Return an Updater of the appropriate type depending on the source.
* Return
s
an Updater of the appropriate type depending on the source.
*
* If a directory is provided which contains a module, will return a
* ModuleUpdater.
...
...
@@ -89,7 +40,10 @@ public function __construct($source) {
* @param string $source
* Directory of a Drupal project.
*
* @return Updater
* @return Drupal\Core\Updater\Updater
* A new Drupal\Core\Updater\Updater object.
*
* @throws Drupal\Core\Updater\UpdaterException
*/
public
static
function
factory
(
$source
)
{
if
(
is_dir
(
$source
))
{
...
...
@@ -102,13 +56,15 @@ public static function factory($source) {
}
/**
* Determine which Updater class can operate on the given directory.
* Determine
s
which Updater class can operate on the given directory.
*
* @param string $directory
* Extracted Drupal project.
*
* @return string
* The class name which can work with this project type.
*
* @throws Drupal\Core\Updater\UpdaterException
*/
public
static
function
getUpdaterFromDirectory
(
$directory
)
{
// Gets a list of possible implementing classes.
...
...
@@ -123,7 +79,7 @@ public static function getUpdaterFromDirectory($directory) {
}
/**
*
Figure out
what the most important (or only) info file is in a directory.
*
Determines
what the most important (or only) info file is in a directory.
*
* Since there is no enforcement of which info file is the project's "main"
* info file, this will get one with the same name as the directory, or the
...
...
@@ -152,7 +108,7 @@ public static function findInfoFile($directory) {
}
/**
* Get the name of the project directory (basename).
* Get
s
the name of the project directory (basename).
*
* @todo: It would be nice, if projects contained an info file which could
* provide their canonical name.
...
...
@@ -167,13 +123,15 @@ public static function getProjectName($directory) {
}
/**
* Return the project name from a Drupal info file.
* Return
s
the project name from a Drupal info file.
*
* @param string $directory
* Directory to search for the info file.
*
* @return string
* The title of the project.
*
* @throws Drupal\Core\Updater\UpdaterException
*/
public
static
function
getProjectTitle
(
$directory
)
{
$info_file
=
self
::
findInfoFile
(
$directory
);
...
...
@@ -188,7 +146,7 @@ public static function getProjectTitle($directory) {
}
/**
* Store the default parameters for the Updater.
* Store
s
the default parameters for the Updater.
*
* @param array $overrides
* An array of overrides for the default parameters.
...
...
@@ -206,9 +164,9 @@ protected function getInstallArgs($overrides = array()) {
}
/**
* Updates a Drupal project
,
returns a list of next actions.
* Updates a Drupal project
and
returns a list of next actions.
*
* @param
FileTransfer
$filetransfer
* @param
Drupal\Core\FileTransfer\FileTransferInterface
$filetransfer
* Object that is a child of FileTransfer. Used for moving files
* to the server.
* @param array $overrides
...
...
@@ -216,6 +174,9 @@ protected function getInstallArgs($overrides = array()) {
*
* @return array
* An array of links which the user may need to complete the update
*
* @throws Drupal\Core\Updater\UpdaterException
* @throws Drupal\Core\Updater\UpdaterFileTransferException
*/
public
function
update
(
&
$filetransfer
,
$overrides
=
array
())
{
try
{
...
...
@@ -264,13 +225,15 @@ public function update(&$filetransfer, $overrides = array()) {
/**
* Installs a Drupal project, returns a list of next actions.
*
* @param
FileTransfer
$filetransfer
* @param
Drupal\Core\FileTransfer\FileTransferInterface
$filetransfer
* Object that is a child of FileTransfer.
* @param array $overrides
* An array of settings to override defaults; see self::getInstallArgs().
*
* @return array
* An array of links which the user may need to complete the install.
*
* @throws Drupal\Core\Updater\UpdaterFileTransferException
*/
public
function
install
(
&
$filetransfer
,
$overrides
=
array
())
{
try
{
...
...
@@ -298,12 +261,14 @@ public function install(&$filetransfer, $overrides = array()) {
}
/**
* Make sure the installation parent directory exists and is writable.
* Make
s
sure the installation parent directory exists and is writable.
*
* @param
FileTransfer
$filetransfer
* @param
Drupal\Core\FileTransfer\FileTransferInterface
$filetransfer
* Object which is a child of FileTransfer.
* @param string $directory
* The installation directory to prepare.
*
* @throws Drupal\Core\Updater\UpdaterException
*/
public
function
prepareInstallDirectory
(
&
$filetransfer
,
$directory
)
{
// Make the parent dir writable if need be and create the dir.
...
...
@@ -341,9 +306,9 @@ public function prepareInstallDirectory(&$filetransfer, $directory) {
}
/**
* Ensure that a given directory is world readable.
* Ensure
s
that a given directory is world readable.
*
* @param
FileTransfer
$filetransfer
* @param
Drupal\Core\FileTransfer\FileTransferInterface
$filetransfer
* Object which is a child of FileTransfer.
* @param string $path
* The file path to make world readable.
...
...
@@ -359,7 +324,7 @@ public function makeWorldReadable(&$filetransfer, $path, $recursive = TRUE) {
}
/**
* Perform a backup.
* Perform
s
a backup.
*
* @todo Not implemented.
*/
...
...
@@ -367,26 +332,26 @@ public function makeBackup(&$filetransfer, $from, $to) {
}
/**
* Return the full path to a directory where backups should be written.
* Return
s
the full path to a directory where backups should be written.
*/
public
function
getBackupDir
()
{
return
file_stream_wrapper_get_instance_by_scheme
(
'temporary'
)
->
getDirectoryPath
();
}
/**
* Perform actions after new code is updated.
* Perform
s
actions after new code is updated.
*/
public
function
postUpdate
()
{
}
/**
* Perform actions after installation.
* Perform
s
actions after installation.
*/
public
function
postInstall
()
{
}
/**
* Return an array of links to pages that should be visited post operation.
* Return
s
an array of links to pages that should be visited post operation.
*
* @return array
* Links which provide actions to take after the install is finished.
...
...
@@ -396,7 +361,7 @@ public function postInstallTasks() {
}
/**
* Return an array of links to pages that should be visited post operation.
* Return
s
an array of links to pages that should be visited post operation.
*
* @return array
* Links which provide actions to take after the update is finished.
...
...
@@ -405,23 +370,3 @@ public function postUpdateTasks() {
return
array
();
}
}
/**
* Exception class for the Updater class hierarchy.
*
* This is identical to the base Exception class, we just give it a more
* specific name so that call sites that want to tell the difference can
* specifically catch these exceptions and treat them differently.
*/
class
UpdaterException
extends
Exception
{
}
/**
* Child class of UpdaterException that indicates a FileTransfer exception.
*
* We have to catch FileTransfer exceptions and wrap those in t(), since
* FileTransfer is so low-level that it doesn't use any Drupal APIs and none
* of the strings are translated.
*/
class
UpdaterFileTransferException
extends
UpdaterException
{
}
core/lib/Drupal/Core/Updater/UpdaterException.php
0 → 100644
View file @
368cf30d
<?php
/**
* @file
* Definition of Drupal\Core\Updater\UpdaterException.
*/
namespace
Drupal\Core\Updater
;
/**
* Defines a Exception class for the Drupal\Core\Updater\Updater class
* hierarchy.
*
* This is identical to the base Exception class, we just give it a more
* specific name so that call sites that want to tell the difference can
* specifically catch these exceptions and treat them differently.
*/
class
UpdaterException
extends
Exception
{
}
core/lib/Drupal/Core/Updater/UpdaterFileTransferException.php
0 → 100644
View file @
368cf30d
<?php
/**
* @file
* Definition of Drupal\Core\Updater\UpdaterFileTransferException.
*/
namespace
Drupal\Core\Updater
;
/**
* Defines a child class of Drupal\Core\Updater\UpdaterException that indicates
* a Drupal\Core\FileTransfer\FileTransferInterface exception.
*
* We have to catch Drupal\Core\FileTransfer\FileTransferInterface exceptions
* and wrap those in t(), since Drupal\Core\FileTransfer\FileTransferInterface
* is so low-level that it doesn't use any Drupal APIs and none of the strings
* are translated.
*/
class
UpdaterFileTransferException
extends
UpdaterException
{
}
core/lib/Drupal/Core/Updater/UpdaterInterface.php
0 → 100644
View file @
368cf30d
<?php
/**
* @file
* Definition of Drupal\Core\Updater\UpdaterInterface.
*/
namespace
Drupal\Core\Updater
;
/**
* Defines an interface for a class which can update a Drupal project.
*