TYPO3 API  SVNRelease
class.tx_em_repository.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010 Marcus Krause <marcus#exp2010@t3sec.info>
00006  *         Steffen Kamper <info@sk-typo3.de>
00007  *  All rights reserved
00008  *
00009  *  This script is part of the TYPO3 project. The TYPO3 project is
00010  *  free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  The GNU General Public License can be found at
00016  *  http://www.gnu.org/copyleft/gpl.html.
00017  *
00018  *  This script is distributed in the hope that it will be useful,
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  *  GNU General Public License for more details.
00022  *
00023  *  This copyright notice MUST APPEAR in all copies of the script!
00024  ***************************************************************/
00025 /**
00026  * class.tx_em_repository.php
00027  *
00028  * Module: Extension manager - Repository
00029  *
00030  * $Id: class.tx_em_repository.php 2082 2010-03-21 17:19:42Z steffenk $
00031  *
00032  * @author  Marcus Krause <marcus#exp2010@t3sec.info>
00033  * @author  Steffen Kamper <info@sk-typo3.de>
00034  */
00035 
00036 
00037 /**
00038  * Repository object for extension manager.
00039  *
00040  * @author    Marcus Krause <marcus#exp2010@t3sec.info>
00041  * @author    Steffen Kamper <info@sk-typo3.de>
00042  *
00043  * @since      2010-02-11
00044  * @package  TYPO3
00045  * @subpackage  EM
00046  */
00047 class tx_em_Repository {
00048 
00049     /**
00050      * Keeps repository identifier.
00051      *
00052      * @var  string
00053      */
00054     protected $id;
00055 
00056     /**
00057      * Keeps repository title.
00058      *
00059      * @var  string
00060      */
00061     protected $title;
00062 
00063     /**
00064      * Keeps repository description.
00065      *
00066      * @var  string
00067      */
00068     protected $description;
00069 
00070     /**
00071      * Keeps repository priority.
00072      *
00073      * @var  integer
00074      */
00075     protected $priority;
00076 
00077     /**
00078      * Keeps mirror list URL.
00079      *
00080      * @var  string
00081      */
00082     protected $mirrorListUrl;
00083 
00084     /**
00085      * Keeps repository mirrors object.
00086      *
00087      * @var  em_repository_mirrors
00088      */
00089     protected $mirrors;
00090 
00091     /**
00092      * Keeps wsdl URL.
00093      *
00094      * @var  string
00095      */
00096     protected $wsdlUrl;
00097 
00098     /**
00099      * Keeps last update.
00100      *
00101      * @var  string
00102      */
00103     protected $lastUpdate;
00104 
00105     /**
00106      * Keeps extension count.
00107      *
00108      * @var  string
00109      */
00110     protected $extensionCount;
00111 
00112 
00113     /**
00114      * Class constructor.
00115      *
00116      * Initializes repository with properties of TYPO3.org main repository.
00117      *
00118      * @access  public
00119      * @return  void
00120      */
00121     function __construct($uid = 1) {
00122         $row = tx_em_Database::getRepositoryByUID($uid);
00123         if (!is_array($row) && $uid === 1) {
00124             $this->fixMainRepository();
00125         } else {
00126             $this->setTitle($row['title']);
00127             $this->setDescription($row['description']);
00128             $this->setId($row['uid']);
00129             $this->setPriority(1);
00130             $this->setMirrorListUrl($row['mirror_url']);
00131             $this->setWsdlUrl($row['wsdl_url']);
00132             $this->setLastUpdate($row['lastUpdated']);
00133             $this->setExtensionCount($row['extCount']);
00134         }
00135     }
00136 
00137     /**
00138      * Method returns uid of a repository.
00139      *
00140      * @access  public
00141      * @return  int  ID of a repository
00142      * @see  $id, setId()
00143      */
00144     public function getId() {
00145         return $this->id;
00146     }
00147 
00148     /**
00149      * Method sets uid of a repository.
00150      *
00151      * @access  public
00152      * @param   string  $id  ID of repository to set
00153      * @return  void
00154      * @see  $id, getId()
00155      */
00156     public function setId($id) {
00157         $this->id = intval($id);
00158     }
00159 
00160     /**
00161      * Method returns title of a repository.
00162      *
00163      * @access  public
00164      * @return  string  title of repository
00165      * @see  $title, setTitle()
00166      */
00167     public function getTitle() {
00168         return $this->title;
00169     }
00170 
00171     /**
00172      * Method sets title of a repository.
00173      *
00174      * @access  public
00175      * @param   string  $title  title of repository to set
00176      * @return  void
00177      * @see  $title, getTitle()
00178      */
00179     public function setTitle($title) {
00180         if (!empty($title) && is_string($title)) {
00181             $this->title = $title;
00182         }
00183     }
00184 
00185     /**
00186      * Method returns description of a repository.
00187      *
00188      * @access  public
00189      * @return  string  title of repository
00190      * @see  $title, setTitle()
00191      */
00192     public function getDescription() {
00193         return $this->description;
00194     }
00195 
00196     /**
00197      * Method sets description of a repository.
00198      *
00199      * @access  public
00200      * @param   string  $description  title of repository to set
00201      * @return  void
00202      */
00203     public function setDescription($description) {
00204         if (!empty($description) && is_string($description)) {
00205             $this->description = $description;
00206         }
00207     }
00208 
00209     /**
00210      * Method returns priority of a repository.
00211      *
00212      * The repository with lowest priority value takes precedence over
00213      * those that have a higher value.
00214      *
00215      * @access  public
00216      * @return  integer
00217      * @see  $priority, setPriority()
00218      * @todo    repository priority is currently unused
00219      */
00220     public function getPriority() {
00221         return $this->priority;
00222     }
00223 
00224     /**
00225      * Method sets priority of a repository.
00226      *
00227      * The repository with lowest priority value takes precedence over
00228      * those that have a higher value.
00229      *
00230      * @access  public
00231      * @param   integer  $priority  priority value to set
00232      * @return  void
00233      * @see  $priority, getPriority()
00234      * @todo    repository priority is currently unused
00235      */
00236     public function setPriority($priority) {
00237         if (!empty($priority) && is_int($priority)) {
00238             $this->priority = $priority;
00239         }
00240     }
00241 
00242     /**
00243      * Method returns URL of a ressource that contains repository mirrors.
00244      *
00245      * @access  public
00246      * @return  string  URL of file that contains repository mirros
00247      * @see  $mirrorListUrl, getMirrorListUrl()
00248      */
00249     public function getMirrorListUrl() {
00250         return $this->mirrorListUrl;
00251     }
00252 
00253     /**
00254      * Method sets URL of a ressource that contains repository mirrors.
00255      *
00256      * Parameter is typically a remote gzipped xml file.
00257      *
00258      * @access  public
00259      * @param   string  $url  URL of file that contains repository mirros
00260      * @return  void
00261      * @see  $mirrorListUrl, getMirrorListUrl()
00262      */
00263     public function setMirrorListUrl($url) {
00264         if (empty($url) || (!empty($url) && t3lib_div::isValidUrl($url))) {
00265             $this->mirrorListUrl = $url;
00266         }
00267     }
00268 
00269     /**
00270      * Method returns URL of repository WSDL.
00271      *
00272      * @access  public
00273      * @return  string  URL of repository WSDL
00274      * @see  $wsdlUrl, setWsdlUrl()
00275      */
00276     public function getWsdlUrl() {
00277         return $this->wsdlUrl;
00278     }
00279 
00280     /**
00281      * Method sets URL of repository WSDL.
00282      *
00283      * @access  public
00284      * @param   string  $url  URL of repository WSDL
00285      * @return  void
00286      * @see  $wsdlUrl, getWsdlUrl()
00287      */
00288     public function setWsdlUrl($url) {
00289         if (!empty($url) && t3lib_div::isValidUrl($url)) {
00290             $this->wsdlUrl = $url;
00291         }
00292     }
00293 
00294     /**
00295      * Method returns LastUpdate.
00296      *
00297      * @access  public
00298      * @return  int  timestamp of last update
00299      */
00300     public function getLastUpdate() {
00301         return $this->lastUpdate;
00302     }
00303 
00304     /**
00305      * Method sets LastUpdate.
00306      *
00307      * @access  public
00308      * @param   int  $time  URL of repository WSDL
00309      * @return  void
00310      */
00311     public function setLastUpdate($time) {
00312         $this->lastUpdate = $time;
00313     }
00314 
00315     /**
00316      * Method returns extension count
00317      *
00318      * @access  public
00319      * @return  int count of readed extensions
00320      */
00321     public function getExtensionCount() {
00322         return $this->extensionCount;
00323     }
00324 
00325     /**
00326      * Method sets extension count
00327      *
00328      * @access  public
00329      * @param   string  $count count of readed extensions
00330      * @return  void
00331      */
00332     public function setExtensionCount($count) {
00333         $this->extensionCount = $count;
00334     }
00335 
00336     /**
00337      * Method registers repository mirrors object.
00338      *
00339      * Repository mirrors object is passed by reference.
00340      *
00341      * @access  public
00342      * @param   em_repository_mirrors  &$mirrors  instance of {@link em_repository_mirrors repository mirrors} class
00343      * @return  void
00344      * @see  $mirrors, getMirrors(), hasMirrors(), removeMirrors()
00345      */
00346     public function addMirrors(tx_em_Repository_Mirrors &$mirrors) {
00347         $this->mirrors = $mirrors;
00348     }
00349 
00350     /**
00351      * Method returns information if a repository mirrors
00352      * object has been registered to this repository.
00353      *
00354      * @access  public
00355      * @return  boolean  true, if a repository mirrors object has been registered, otherwise false
00356      * @see  $mirrors, addMirrors(), getMirrors(), removeMirrors()
00357      */
00358     public function hasMirrors() {
00359         $hasMirrors = FALSE;
00360         if (is_object($this->mirrors)) {
00361             $hasMirrors = TRUE;
00362         }
00363         return $hasMirrors;
00364     }
00365 
00366     /**
00367      * Method returns a repository mirrors object.
00368      *
00369      * @access  public
00370      * @return  em_repository_mirrors  registered instance of {@link em_repository_mirrors repository mirrors} class or NULL
00371      * @see  $mirrors, addMirrors(), hasMirrors(), removeMirrors()
00372      */
00373     public function getMirrors() {
00374         return $this->hasMirrors() ? $this->mirrors : NULL;
00375     }
00376 
00377     /**
00378      * Method unregisters a repository mirrors object.
00379      *
00380      * @access  public
00381      * @return  void
00382      * @see  $mirrors, addMirrors(), getMirrors(), hasMirrors()
00383      */
00384     public function removeMirrors() {
00385         unset($this->mirrors);
00386     }
00387 
00388     /**
00389      * Insert main repository if not present
00390      *
00391      * @return void
00392      */
00393     protected function fixMainRepository() {
00394         $this->setTitle('TYPO3.org Main Repository');
00395         $this->setId('1');
00396         $this->setPriority(1);
00397         $this->setDescription('Main repository on typo3.org. For extension download there are mirrors available.');
00398         $this->setMirrorListUrl('http://repositories.typo3.org/mirrors.xml.gz');
00399         $this->setWsdlUrl('http://typo3.org/wsdl/tx_ter_wsdl.php');
00400         tx_em_Database::insertRepository($this);
00401     }
00402 }
00403 
00404 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/repository/class.tx_em_repository.php'])) {
00405     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/repository/class.tx_em_repository.php']);
00406 }
00407 
00408 ?>