tests - add autogenerated comment blocks
[civicrm-core.git] / tools / bin / scripts / cli.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
34cd78e1 4 | CiviCRM version 4.5 |
6a488035
TO
5 +--------------------------------------------------------------------+
6 | Copyright Tech To The People http:tttp.eu (c) 2008 |
7 +--------------------------------------------------------------------+
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License along with this program; if not, contact CiviCRM LLC |
20 | at info[AT]civicrm[DOT]org. If you have questions about the |
21 | GNU Affero General Public License or the licensing of CiviCRM, |
22 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
23 +--------------------------------------------------------------------+
24*/
25
26/**
27 * A PHP shell script
28
29 On drupal if you have a symlink to your civi module, don't forget to create a new file - settings_location.php
30 Enter the following code (substitute the actual location of your <drupal root>/sites directory)
31 <?php
32 define( 'CIVICRM_CONFDIR', '/var/www/drupal.6/sites' );
33 ?>
34
35 */
bed96570 36$include_path = "../packages/:" . get_include_path();
6a488035
TO
37set_include_path($include_path);
38class civicrm_CLI {
39
40 /**
41 * constructor
42 */
43 function __construct() {
44 // $include_path = "packages/" . get_include_path( );
45 // set_include_path( $include_path );
46 require_once 'Console/Getopt.php';
47 $shortOptions = "s:u:p:k:";
48 $longOptions = array('site=', 'user', 'pass');
49
50 $getopt = new Console_Getopt();
51 $args = $getopt->readPHPArgv();
52 array_shift($args);
53 list($valid, $this->args) = $getopt->getopt2($args, $shortOptions, $longOptions);
54
55 $vars = array(
56 'user' => 'u',
57 'pass' => 'p',
58 'key' => 'k',
59 'site' => 's',
60 );
61
62 foreach ($vars as $var => $short) {
63 $$var = NULL;
64 foreach ($valid as $v) {
65 if ($v[0] == $short || $v[0] == "--$var") {
66 $$var = $v[1];
67 break;
68 }
69 }
70 if (!$$var) {
71 die("\nUsage: $ php5 " . $_SERVER['PHP_SELF'] . " -k key -u user -p password -s yoursite.org\n");
72 }
73 }
74 $this->site = $site;
75 $this->key = $key;
76 $this->setEnv();
77 $this->authenticate($user, $pass);
78 }
79
80 function authenticate($user, $pass) {
81 session_start();
82 require_once 'CRM/Core/Config.php';
83
84 $config = &CRM_Core_Config::singleton();
85
86 // this does not return on failure
87 // require_once 'CRM/Utils/System.php';
88 // CRM_Utils_System::authenticateScript( true );
89 CRM_Utils_System::authenticateScript(TRUE, $user, $pass);
90 }
91
92 function setEnv() {
93 // so the configuration works with php-cli
94 $_SERVER['PHP_SELF'] = "/index.php";
95 $_SERVER['HTTP_HOST'] = $this->site;
96 $_REQUEST['key'] = $this->key;
97 require_once ("./civicrm.config.php");
98 }
99}
100
101
102//$cli=new civicrm_cli ();
103