General purpose class managing the plugins source code files deployment.
More...
|
string | $dirroot |
| full path to the Moodle app directory root
|
|
string | $temproot |
| full path to the temp directory root
|
|
General purpose class managing the plugins source code files deployment.
The class is able and supposed to
- fetch and cache ZIP files distributed via the Moodle Plugins directory
- unpack the ZIP files in a temporary storage
- archive existing version of the plugin source code
- move (deploy) the plugin source code into the $CFG->dirroot
- Copyright
- 2015 David Mudrak david.nosp@m.@moo.nosp@m.dle.c.nosp@m.om
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
◆ __construct()
core\update\code_manager::__construct |
( |
|
$dirroot = null , |
|
|
|
$temproot = null |
|
) |
| |
Instantiate the class instance.
- Parameters
-
string | $dirroot | full path to the moodle app directory root |
string | $temproot | full path to our temp directory |
◆ archive_plugin_version()
core\update\code_manager::archive_plugin_version |
( |
|
$folderpath, |
|
|
|
$component, |
|
|
|
$version, |
|
|
|
$overwrite = false |
|
) |
| |
Archive the current plugin on-disk version.
- Parameters
-
string | $folderpath | full path to the plugin folder |
string | $component | |
int | $version | |
bool | $overwrite | overwrite existing archive if found |
- Return values
-
◆ debug()
core\update\code_manager::debug |
( |
|
$msg | ) |
|
|
protected |
Raise developer debugging level message.
- Parameters
-
◆ download_file_content()
core\update\code_manager::download_file_content |
( |
|
$url, |
|
|
|
$tofile |
|
) |
| |
|
protected |
Thin wrapper for the core's download_file_content() function.
- Parameters
-
string | $url | URL to the file |
string | $tofile | full path to where to store the downloaded file |
- Return values
-
◆ download_plugin_zip_file()
core\update\code_manager::download_plugin_zip_file |
( |
|
$url, |
|
|
|
$tofile |
|
) |
| |
|
protected |
Download the ZIP file with the plugin package from the given location.
- Parameters
-
string | $url | URL to the file |
string | $tofile | full path to where to store the downloaded file |
- Return values
-
◆ get_archived_plugin_version()
core\update\code_manager::get_archived_plugin_version |
( |
|
$component, |
|
|
|
$version |
|
) |
| |
Return the path to the ZIP file with the archive of the given plugin version.
- Parameters
-
string | $component | |
int | $version | |
- Return values
-
string|bool | false if not found, full path otherwise |
◆ get_plugin_zip_root_dir()
core\update\code_manager::get_plugin_zip_root_dir |
( |
|
$zipfilepath | ) |
|
Detects the plugin's name from its ZIP file.
Plugin ZIP packages are expected to contain a single directory and the directory name would become the plugin name once extracted to the Moodle dirroot.
- Parameters
-
string | $zipfilepath | full path to the ZIP files |
- Return values
-
string|bool | false on error |
◆ get_remote_plugin_zip()
core\update\code_manager::get_remote_plugin_zip |
( |
|
$url, |
|
|
|
$md5 |
|
) |
| |
Obtain the plugin ZIP file from the given URL.
The caller is supposed to know both downloads URL and the MD5 hash of the ZIP contents in advance, typically by using the API requests against the plugins directory.
- Parameters
-
- Return values
-
string|bool | full path to the file, false on error |
◆ list_plugin_folder_files()
core\update\code_manager::list_plugin_folder_files |
( |
|
$folderpath | ) |
|
Returns list of all files in the given directory.
Given a path like /full/path/to/mod/workshop, it returns array like
[workshop/] => /full/path/to/mod/workshop [workshop/lang/] => /full/path/to/mod/workshop/lang [workshop/lang/workshop.php] => /full/path/to/mod/workshop/lang/workshop.php ...
Which mathes the format used by Moodle file packers.
- Parameters
-
string | $folderpath | full path to the plugin directory |
- Return values
-
array | (string)relpath => (string)fullpath |
◆ move_extracted_plugin_files()
core\update\code_manager::move_extracted_plugin_files |
( |
|
$sourcedir, |
|
|
|
$targetdir, |
|
|
array |
$files |
|
) |
| |
|
protected |
Moves the extracted contents of the plugin ZIP into the target location.
- Parameters
-
string | $sourcedir | full path to the directory the ZIP file was extracted to |
mixed | $targetdir | full path to the directory where the files should be moved to |
array | $files | list of extracted files |
◆ rename_extracted_rootdir()
core\update\code_manager::rename_extracted_rootdir |
( |
|
$dirname, |
|
|
|
$rootdir, |
|
|
array |
$files |
|
) |
| |
|
protected |
Renames the root directory of the extracted ZIP package.
This internal helper method assumes that the plugin ZIP package has been extracted into a temporary empty directory so the plugin folder is the only folder there. The ZIP package is supposed to be validated so that it contains just a single root folder.
- Parameters
-
string | $dirname | fullpath location of the extracted ZIP package |
string | $rootdir | the requested name of the root directory |
array | $files | list of extracted files |
- Return values
-
array | eventually amended list of extracted files |
◆ set_plugin_files_permissions()
core\update\code_manager::set_plugin_files_permissions |
( |
|
$targetdir, |
|
|
array |
$files |
|
) |
| |
|
protected |
Sets the permissions of extracted subdirs and files.
As a result of unzipping, the subdirs and files are created with permissions set to $CFG->directorypermissions and $CFG->filepermissions. These are too benevolent by default (777 and 666 respectively) for PHP scripts and may lead to HTTP 500 errors in some environments.
To fix this behaviour, we inherit the permissions of the plugin root directory itself.
- Parameters
-
string | $targetdir | full path to the directory the ZIP file was extracted to |
array | $files | list of extracted files |
◆ unzip_plugin_file()
core\update\code_manager::unzip_plugin_file |
( |
|
$zipfilepath, |
|
|
|
$targetdir, |
|
|
|
$rootdir = '' |
|
) |
| |
Extracts the saved plugin ZIP file.
Returns the list of files found in the ZIP. The format of that list is array of (string)filerelpath => (bool|string) where the array value is either true or a string describing the problematic file.
- See also
- zip_packer::extract_to_pathname()
- Parameters
-
string | $zipfilepath | full path to the saved ZIP file |
string | $targetdir | full path to the directory to extract the ZIP file to |
string | $rootdir | explicitly rename the root directory of the ZIP into this non-empty value |
- Return values
-
◆ zip_plugin_folder()
core\update\code_manager::zip_plugin_folder |
( |
|
$folderpath, |
|
|
|
$targetzip |
|
) |
| |
Make an archive backup of the existing plugin folder.
- Parameters
-
string | $folderpath | full path to the plugin folder |
string | $targetzip | full path to the zip file to be created |
- Return values
-
bool | true if file created, false if not |
The documentation for this class was generated from the following file: