]> dev.renevier.net Git - syj.git/commitdiff
call cron scripts with php cli
authorarno <arno@renevier.net>
Mon, 14 Mar 2011 16:21:55 +0000 (17:21 +0100)
committerarno <arno@renevier.net>
Mon, 14 Mar 2011 16:21:55 +0000 (17:21 +0100)
application/Bootstrap.php
application/configs/application.ini
application/controllers/CronController.php [deleted file]
application/crons/pending.php [new file with mode: 0644]
public/index.php
public/init.php [new file with mode: 0644]
scripts/cron.php [new file with mode: 0755]
scripts/crontab.syj

index 08816c00be5d778f194331ce775dd4431f7b1691..5da7d3e218aa93533a938652c4da1edecfe43c38 100644 (file)
@@ -47,4 +47,3 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
     }
 
 }
-
index 3c743966438b847009aee82eee8f71548c6d0286..cb9d2cce46de965c16073e5c8b66097fb1b5156e 100644 (file)
@@ -90,10 +90,6 @@ resources.router.routes.pending.defaults.action = "index"
 resources.router.routes.termsofuse.route = "termsofuse/"
 resources.router.routes.termsofuse.defaults.controller = "termsofuse"
 resources.router.routes.termsofuse.defaults.action = "index"
-; cron/
-resources.router.routes.cron.route = "cron/"
-resources.router.routes.cron.defaults.controller = "cron"
-resources.router.routes.cron.defaults.action = "index"
 ; newpwd/
 resources.router.routes.newpwd.route = "newpwd/"
 resources.router.routes.newpwd.defaults.controller = "newpwd"
diff --git a/application/controllers/CronController.php b/application/controllers/CronController.php
deleted file mode 100644 (file)
index e8ab6ec..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-/*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
-    and is published under the AGPL license. */
-
-class CronController extends Zend_Controller_Action
-{
-    public function init() {
-        $ip = $this->getRequest()->getClientIp(true);
-        if ($ip !== '127.0.0.1' and $ip !== '::1') {
-            throw new Syj_Exception_Forbidden();
-        }
-    }
-    public function indexAction() {
-        $mapper = new Syj_Model_PendingMapper();
-        foreach ($mapper->fetchAll() as $pending) {
-            $pending->notify();
-        }
-        $this->_helper->SyjApi->setCode(200);
-    }
-}
diff --git a/application/crons/pending.php b/application/crons/pending.php
new file mode 100644 (file)
index 0000000..fc6d1ab
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+$mapper = new Syj_Model_PendingMapper();
+foreach ($mapper->fetchAll() as $pending) {
+    $pending->notify();
+}
index f38470ed27adac05dfd59c47fdd09b915792d073..b2a875f860cac7448b26d3d358d51f792880f1dd 100644 (file)
@@ -1,32 +1,5 @@
 <?php
 
-// Define path to application directory
-defined('APPLICATION_PATH')
-    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
+require_once ('init.php');
 
-// Define application environment
-defined('APPLICATION_ENV')
-    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
-
-// set include directories to '.' and ../library
-set_include_path('.' . PATH_SEPARATOR . realpath(APPLICATION_PATH . '/../library'));
-
-/** Zend_Application */
-require_once 'Zend/Application.php';
-
-// Create application, bootstrap, and run
-$application = new Zend_Application(
-    APPLICATION_ENV,
-    APPLICATION_PATH . '/configs/application.ini'
-);
-
-# we use this function as a marker so xgettext knows it must extract this
-# string. This function can be used when string must be translated, but not at
-# the place it's called. For example, Zend_Form uses a translator to translate
-# string it has been given. So, we must pass it a non translated string.
-function __($str) {
-    return $str;
-}
-
-$application->bootstrap()
-            ->run();
+$application->bootstrap()->run();
diff --git a/public/init.php b/public/init.php
new file mode 100644 (file)
index 0000000..4780fe3
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+// Define path to application directory
+defined('APPLICATION_PATH')
+    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
+
+// Define application environment
+defined('APPLICATION_ENV')
+    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
+
+// set include directories to '.' and ../library
+set_include_path('.' . PATH_SEPARATOR . realpath(APPLICATION_PATH . '/../library'));
+
+/** Zend_Application */
+require_once 'Zend/Application.php';
+
+# we use this function as a marker so xgettext knows it must extract this
+# string. This function can be used when string must be translated, but not at
+# the place it's called. For example, Zend_Form uses a translator to translate
+# string it has been given. So, we must pass it a non translated string.
+function __($str) {
+    return $str;
+}
+
+$application = new Zend_Application(
+    APPLICATION_ENV,
+    APPLICATION_PATH . '/configs/application.ini'
+);
diff --git a/scripts/cron.php b/scripts/cron.php
new file mode 100755 (executable)
index 0000000..d351280
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/env php
+<?php
+
+require_once realpath(dirname(__FILE__) . '/../public/init.php');
+
+$application->bootstrap();
+
+foreach (glob(realpath(APPLICATION_PATH . '/crons') . '/*.php') as $fname) {
+    require_once ($fname);
+}
index cf80bef8bc5f9279d621b420049264a8d229e65e..53159e907448cead95c8166102c5083666fdd30f 100644 (file)
@@ -1,6 +1,6 @@
 MAILTO=arno@renevier.net
 # every 5 minutes, call syj php cron
-*/5 * * * * /usr/bin/wget --header="Host: osm-syj.crans.org" http://localhost/cron -O /dev/null  -o /dev/null
+*/5 * * * * /data/project/syj/scripts/cron.php
 # every month, update geoip db
 12 3 3 * * /data/project/syj/scripts/updategeoip.sh
 # every day, delete old sessions files