From 0990161c720c6b5202a59a91e3b7aa172374f277 Mon Sep 17 00:00:00 2001
From: Michael Hamann <michael@content-space.de>
Date: Sun, 8 Jul 2012 19:20:48 +0200
Subject: [PATCH] Add cli support to farm implementation

Now the animal can be specified in the animal environment variable.
---
 inc/farm.php | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/inc/farm.php b/inc/farm.php
index 4cbffc99f..8434e3067 100644
--- a/inc/farm.php
+++ b/inc/farm.php
@@ -41,12 +41,15 @@ if(!defined('DOKU_FARM')) define('DOKU_FARM', false);
  */
 function conf_path($farm) {
 
-    // htaccess based
-    if(isset($_REQUEST['animal'])) {
-        if(!is_dir($farm.'/'.$_REQUEST['animal']))
+    // htaccess based or cli
+    // cli usage example: animal=your_animal bin/indexer.php
+    if(isset($_REQUEST['animal']) || ('cli' == php_sapi_name() && isset($_SERVER['animal']))) {
+        $mode = isset($_REQUEST['animal']) ? 'htaccess' : 'cli';
+        $animal = $mode == 'htaccess' ? $_REQUEST['animal'] : $_SERVER['animal'];
+        if(!is_dir($farm.'/'.$animal))
             nice_die("Sorry! This Wiki doesn't exist!");
-        if(!defined('DOKU_FARM')) define('DOKU_FARM', 'htaccess');
-        return $farm.'/'.$_REQUEST['animal'].'/conf/';
+        if(!defined('DOKU_FARM')) define('DOKU_FARM', $mode);
+        return $farm.'/'.$animal.'/conf/';
     }
 
     // virtual host based
-- 
GitLab