Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Public Attributes | List of all members
component_installer Class Reference

This class is used to check, download and install items from download.moodle.org to the moodledata directory. More...

Public Member Functions

 __construct ($sourcebase, $zippath, $zipfilename, $md5filename='', $destpath='')
 Array of cached components to avoid to. More...
 
 change_zip_file ($newzipfilename)
 This function will change the zip file to install on the fly to allow the class to process different components of the same md5 file without intantiating more objects. More...
 
object check_requisites ()
 This function will check if everything is properly set to begin one installation. More...
 
 component_installer ($sourcebase, $zippath, $zipfilename, $md5filename='', $destpath='')
 Old syntax of class constructor. More...
 
 get_all_components_md5 ()
 This function allows you to retrieve the complete array of components found in the md5filename. More...
 
 get_component_md5 ()
 This function will download the specified md5 file, looking for the current componentname, returning its md5 field and storing extramd5info if present. More...
 
 get_error ()
 This function returns the errorstring. More...
 
 get_extra_md5_field ()
 This function returns the extramd5 field (optional in md5 file) More...
 
object get_local_md5 ()
 This function will get the local md5 value of the installed component. More...
 
 install ()
 This function will perform the full installation if needed, i.e. More...
 
 need_upgrade ()
 This function will detect if remote component needs to be installed because it's different from the local one. More...
 

Public Attributes

array $cachedmd5components
 Flag to see if requisites check has been passed ok.
 
 $componentname
 Name of the .md5 file to be read.
 
 $destpath
 Name of the component. More...
 
 $errorstring
 Relative path (from moodledata) where the .zip file will be expanded.
 
 $extramd5info
 Latest error produced. It will contain one lang string key.
 
 $md5filename
 Name of the .zip file to be downloaded.
 
 $requisitesok
 Contents of the optional third field in the .md5 file.
 
string $sourcebase
 
 $zipfilename
 Relative path (from sourcebase) where the downloadeable item resides.
 
 $zippath
 Full http URL, base for downloadable items.
 

Detailed Description

This class is used to check, download and install items from download.moodle.org to the moodledata directory.

It always return true/false in all their public methods to say if execution has ended succesfuly or not. If there is any problem its getError() method can be called, returning one error string to be used with the standard get/print_string() functions.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

component_installer::__construct (   $sourcebase,
  $zippath,
  $zipfilename,
  $md5filename = '',
  $destpath = '' 
)

Array of cached components to avoid to.

download the same md5 file more than once per request. Standard constructor of the class. It will initialize all attributes. without performing any check at all.

Parameters
string$sourcebaseFull http URL, base for downloadeable items
string$zippathRelative path (from sourcebase) where the downloadeable item resides
string$zipfilenameName of the .zip file to be downloaded
string$md5filenameName of the .md5 file to be read (default '' = same than zipfilename)
string$destpathRelative path (from moodledata) where the .zip file will be expanded (default='' = moodledataitself)
Return values
object

Member Function Documentation

◆ change_zip_file()

component_installer::change_zip_file (   $newzipfilename)

This function will change the zip file to install on the fly to allow the class to process different components of the same md5 file without intantiating more objects.

Parameters
string$newzipfilenameNew zip filename to process
Return values
booleantrue/false

◆ check_requisites()

object component_installer::check_requisites ( )

This function will check if everything is properly set to begin one installation.

Also, it will check for required settings and will fill everything as needed.

Return values
booleantrue/false (plus detailed error in errorstring)

◆ component_installer()

component_installer::component_installer (   $sourcebase,
  $zippath,
  $zipfilename,
  $md5filename = '',
  $destpath = '' 
)

Old syntax of class constructor.

Deprecated in PHP7.

Deprecated:
since Moodle 3.1

◆ get_all_components_md5()

component_installer::get_all_components_md5 ( )

This function allows you to retrieve the complete array of components found in the md5filename.

Return values
bool|arrayarray of components in md5 file or false if error

◆ get_component_md5()

component_installer::get_component_md5 ( )

This function will download the specified md5 file, looking for the current componentname, returning its md5 field and storing extramd5info if present.

Also it caches results to cachedmd5components for better performance in the same request.

Return values
mixedmd5 present in server (or false if error)

◆ get_error()

component_installer::get_error ( )

This function returns the errorstring.

Return values
stringthe error string

◆ get_extra_md5_field()

component_installer::get_extra_md5_field ( )

This function returns the extramd5 field (optional in md5 file)

Return values
stringthe extramd5 field

◆ get_local_md5()

object component_installer::get_local_md5 ( )

This function will get the local md5 value of the installed component.

Return values
bool|stringmd5 of the local component (false on error)

◆ install()

component_installer::install ( )

This function will perform the full installation if needed, i.e.

compare md5 values, download, unzip, install and regenerate local md5 file

@uses COMPONENT_ERROR @uses COMPONENT_UPTODATE @uses COMPONENT_ERROR @uses COMPONENT_INSTALLED

Return values
intCOMPONENT_(ERROR | UPTODATE | INSTALLED)

◆ need_upgrade()

component_installer::need_upgrade ( )

This function will detect if remote component needs to be installed because it's different from the local one.

@uses COMPONENT_ERROR @uses COMPONENT_UPTODATE @uses COMPONENT_NEEDUPDATE

Return values
intCOMPONENT_(ERROR | UPTODATE | NEEDUPDATE)

Member Data Documentation

◆ $destpath

component_installer::$destpath

Name of the component.

Must be the zip name without the extension. And it defines a lot of things: the md5 line to search for, the default m5 file name and the name of the root dir stored inside the zip file


The documentation for this class was generated from the following file: