Runonce Code Beispiele: Unterschied zwischen den Versionen
Aus Contao Community Documentation
K |
(→Code Beispiel Spezialfall) |
||
| Zeile 6: | Zeile 6: | ||
== Code Beispiele == | == Code Beispiele == | ||
== Code Beispiel Spezialfall == | == Code Beispiel Spezialfall == | ||
| + | Universal Runonce von Andreas Schempp, /system/runonce.php | ||
| + | <source lang="php"> | ||
| + | class UniversalRunonce extends Controller | ||
| + | { | ||
| + | |||
| + | /** | ||
| + | * Initialize the object | ||
| + | */ | ||
| + | public function __construct() | ||
| + | { | ||
| + | parent::__construct(); | ||
| + | |||
| + | // Fix potential Exception on line 0 because of __destruct method (see http://dev.contao.org/issues/2236) | ||
| + | $this->import((TL_MODE=='BE' ? 'BackendUser' : 'FrontendUser'), 'User'); | ||
| + | $this->import('Database'); | ||
| + | } | ||
| + | |||
| + | |||
| + | /** | ||
| + | * Execute all runonce files in module config directories | ||
| + | */ | ||
| + | public function run() | ||
| + | { | ||
| + | $this->import('Files'); | ||
| + | $arrModules = scan(TL_ROOT . '/system/modules/'); | ||
| + | |||
| + | foreach ($arrModules as $strModule) | ||
| + | { | ||
| + | if ((@include(TL_ROOT . '/system/modules/' . $strModule . '/config/runonce.php')) !== false) | ||
| + | { | ||
| + | $this->Files->delete('system/modules/' . $strModule . '/config/runonce.php'); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | /** | ||
| + | * Instantiate controller | ||
| + | */ | ||
| + | if (version_compare(VERSION, '2.10', '<')) | ||
| + | { | ||
| + | $objUniversalRunonce = new UniversalRunonce(); | ||
| + | $objUniversalRunonce->run(); | ||
| + | } | ||
| + | </source> | ||
---- | ---- | ||
--[[Benutzer:BugBuster|BugBuster]] 14:17, 13. Nov. 2011 (CET) | --[[Benutzer:BugBuster|BugBuster]] 14:17, 13. Nov. 2011 (CET) | ||
Version vom 13. November 2011, 15:51 Uhr
| betrifft | |
|---|---|
| TYPOlight Version | ab 2.7 |
| Contao Version | ab 2.9 |
Hinweis
| |
Achtung: Artikel wird grad überarbeitet, bitte nichts dran ändern solange dieser Hinweis noch besteht. Dringende Hinweise über IRC an mich. (BugBuster) |
Code Beispiele
Code Beispiel Spezialfall
Universal Runonce von Andreas Schempp, /system/runonce.php
class UniversalRunonce extends Controller { /** * Initialize the object */ public function __construct() { parent::__construct(); // Fix potential Exception on line 0 because of __destruct method (see http://dev.contao.org/issues/2236) $this->import((TL_MODE=='BE' ? 'BackendUser' : 'FrontendUser'), 'User'); $this->import('Database'); } /** * Execute all runonce files in module config directories */ public function run() { $this->import('Files'); $arrModules = scan(TL_ROOT . '/system/modules/'); foreach ($arrModules as $strModule) { if ((@include(TL_ROOT . '/system/modules/' . $strModule . '/config/runonce.php')) !== false) { $this->Files->delete('system/modules/' . $strModule . '/config/runonce.php'); } } } } /** * Instantiate controller */ if (version_compare(VERSION, '2.10', '<')) { $objUniversalRunonce = new UniversalRunonce(); $objUniversalRunonce->run(); }
--BugBuster 14:17, 13. Nov. 2011 (CET)