[BUGFIX] Do not fetch extension list on every request
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Controller / UpdateFromTerController.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 Susanne Moog, <typo3@susannemoog.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Controller for actions relating to update of full extension list from TER
30 *
31 * @author Susanne Moog <typo3@susannemoog.de>
32 * @package Extension Manager
33 * @subpackage Controller
34 */
35 class Tx_Extensionmanager_Controller_UpdateFromTerController extends Tx_Extensionmanager_Controller_AbstractController {
36
37 /**
38 * @var Tx_Extensionmanager_Utility_Repository_Helper
39 */
40 protected $repositoryHelper;
41
42 /**
43 * @var Tx_Extensionmanager_Domain_Repository_RepositoryRepository
44 */
45 protected $repositoryRepository;
46
47 /**
48 * @var Tx_Extensionmanager_Utility_List
49 */
50 protected $listUtility;
51
52 /**
53 * @var Tx_Extensionmanager_Domain_Repository_ExtensionRepository
54 */
55 protected $extensionRepository;
56
57 /**
58 * Dependency injection of the Extension Repository
59 *
60 * @param Tx_Extensionmanager_Domain_Repository_ExtensionRepository $extensionRepository
61 * @return void
62 */
63 public function injectExtensionRepository(Tx_Extensionmanager_Domain_Repository_ExtensionRepository $extensionRepository) {
64 $this->extensionRepository = $extensionRepository;
65 }
66
67 /**
68 * Dependency injection of the Repository Helper Utility
69 *
70 * @param Tx_Extensionmanager_Utility_Repository_Helper $repositoryHelper
71 * @return void
72 */
73 public function injectRepositoryHelper(Tx_Extensionmanager_Utility_Repository_Helper $repositoryHelper) {
74 $this->repositoryHelper = $repositoryHelper;
75 }
76
77 /**
78 * Dependency injection of repository repository
79 *
80 * @param Tx_Extensionmanager_Domain_Repository_RepositoryRepository $repositoryRepository
81 * @return void
82 */
83 public function injectRepositoryRepository(Tx_Extensionmanager_Domain_Repository_RepositoryRepository $repositoryRepository) {
84 $this->repositoryRepository = $repositoryRepository;
85 }
86
87 /**
88 * @param Tx_Extensionmanager_Utility_List $listUtility
89 * @return void
90 */
91 public function injectListUtility(Tx_Extensionmanager_Utility_List $listUtility) {
92 $this->listUtility = $listUtility;
93 }
94
95 /**
96 * Update extension list from TER
97 *
98 * @param boolean $forceUpdateCheck
99 * @return void
100 */
101 public function updateExtensionListFromTerAction($forceUpdateCheck) {
102 $updated = FALSE;
103 $errorMessage = '';
104
105 /** @var $repository Tx_Extensionmanager_Domain_Model_Repository */
106 $repository = $this->repositoryRepository->findOneByUid((int)$this->settings['repositoryUid']);
107 if ($repository->getLastUpdate()->getTimestamp() < ($GLOBALS['EXEC_TIME'] - 24 * 60 * 60) || $forceUpdateCheck) {
108 try {
109 $updated = $this->repositoryHelper->updateExtList();
110 } catch (Tx_Extensionmanager_Exception_ExtensionManager $e) {
111 $errorMessage = $e->getMessage();
112 }
113 }
114 $this->view->assign('updated', $updated)
115 ->assign('repository', $repository)
116 ->assign('errorMessage', $errorMessage);
117 }
118
119 }
120 ?>