2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\DB;
|
|
|
|
use SilverStripe\ORM\DataModel;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2008-02-25 03:10:37 +01:00
|
|
|
* File similar to main.php designed for command-line scripts
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-09-26 23:34:00 +02:00
|
|
|
* This file lets you execute SilverStripe requests from the command-line. The URL is passed as the first argument to
|
|
|
|
* the scripts.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-02-25 03:10:37 +01:00
|
|
|
* @subpackage core
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-01-09 05:18:36 +01:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
/**
|
|
|
|
* Ensure that people can't access this from a web-server
|
|
|
|
*/
|
2016-04-19 08:54:11 +02:00
|
|
|
if(PHP_SAPI != "cli" && PHP_SAPI != "cgi" && PHP_SAPI != "cgi-fcgi") {
|
2008-09-30 01:41:50 +02:00
|
|
|
echo "cli-script.php can't be run from a web request, you have to run it on the command-line.";
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Identify the cli-script.php file and change to its container directory, so that require_once() works
|
|
|
|
*/
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
|
|
|
|
chdir(dirname($_SERVER['SCRIPT_FILENAME']));
|
|
|
|
|
2008-09-25 06:49:01 +02:00
|
|
|
/**
|
|
|
|
* Process arguments and load them into the $_GET and $_REQUEST arrays
|
|
|
|
* For example,
|
|
|
|
* sake my/url somearg otherarg key=val --otherkey=val third=val&fourth=val
|
|
|
|
*
|
2013-06-18 20:28:46 +02:00
|
|
|
* Will result in the following get data:
|
2008-09-25 06:49:01 +02:00
|
|
|
* args => array('somearg', 'otherarg'),
|
|
|
|
* key => val
|
|
|
|
* otherkey => val
|
|
|
|
* third => val
|
|
|
|
* fourth => val
|
|
|
|
*/
|
2008-08-13 03:44:43 +02:00
|
|
|
if(isset($_SERVER['argv'][2])) {
|
2012-12-08 12:20:20 +01:00
|
|
|
$args = array_slice($_SERVER['argv'],2);
|
|
|
|
if(!isset($_GET)) $_GET = array();
|
|
|
|
if(!isset($_REQUEST)) $_REQUEST = array();
|
|
|
|
foreach($args as $arg) {
|
|
|
|
if(strpos($arg,'=') == false) {
|
|
|
|
$_GET['args'][] = $arg;
|
|
|
|
} else {
|
|
|
|
$newItems = array();
|
|
|
|
parse_str( (substr($arg,0,2) == '--') ? substr($arg,2) : $arg, $newItems );
|
|
|
|
$_GET = array_merge($_GET, $newItems);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$_REQUEST = array_merge($_REQUEST, $_GET);
|
2008-08-13 03:44:43 +02:00
|
|
|
}
|
2008-02-25 03:10:37 +01:00
|
|
|
|
2010-12-16 05:04:06 +01:00
|
|
|
// Set 'url' GET parameter
|
|
|
|
if(isset($_SERVER['argv'][1])) {
|
|
|
|
$_REQUEST['url'] = $_SERVER['argv'][1];
|
|
|
|
$_GET['url'] = $_SERVER['argv'][1];
|
|
|
|
}
|
|
|
|
|
2016-05-23 22:40:05 +02:00
|
|
|
// require composers autoloader
|
|
|
|
if (file_exists($autoloadPath = dirname(__DIR__) . '/vendor/autoload.php')) {
|
|
|
|
require_once $autoloadPath;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo "Failed to include composer's autoloader, unable to continue\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
2012-03-24 04:38:57 +01:00
|
|
|
* Include SilverStripe's core code
|
2008-02-25 03:10:37 +01:00
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
require_once("core/Core.php");
|
|
|
|
|
2010-10-15 05:23:57 +02:00
|
|
|
global $databaseConfig;
|
2008-11-22 04:51:04 +01:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
// We don't have a session in cli-script, but this prevents errors
|
|
|
|
$_SESSION = null;
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
require_once("ORM/DB.php");
|
2013-05-30 06:49:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Connect to database
|
|
|
|
if(!isset($databaseConfig) || !isset($databaseConfig['database']) || !$databaseConfig['database']) {
|
|
|
|
echo "\nPlease configure your database connection details. You can do this by creating a file
|
|
|
|
called _ss_environment.php in either of the following locations:\n\n";
|
2013-08-21 08:54:05 +02:00
|
|
|
echo " - " . BASE_PATH . DIRECTORY_SEPARATOR . "_ss_environment.php\n - ";
|
|
|
|
echo dirname(BASE_PATH) . DIRECTORY_SEPARATOR . "_ss_environment.php\n\n";
|
2013-05-30 06:49:43 +02:00
|
|
|
echo <<<ENVCONTENT
|
|
|
|
|
|
|
|
Put the following content into this file:
|
|
|
|
--------------------------------------------------
|
|
|
|
<?php
|
|
|
|
|
|
|
|
/* Change this from 'dev' to 'live' for a production environment. */
|
|
|
|
define('SS_ENVIRONMENT_TYPE', 'dev');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-05-30 06:49:43 +02:00
|
|
|
/* This defines a default database user */
|
|
|
|
define('SS_DATABASE_SERVER', 'localhost');
|
|
|
|
define('SS_DATABASE_USERNAME', '<user>');
|
|
|
|
define('SS_DATABASE_PASSWORD', '<password>');
|
|
|
|
define('SS_DATABASE_NAME', '<database>');
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2014-08-15 08:53:05 +02:00
|
|
|
Once you have done that, run 'composer install' or './framework/sake dev/build' to create
|
2013-05-30 06:49:43 +02:00
|
|
|
an empty database.
|
|
|
|
|
|
|
|
For more information, please read this page in our docs:
|
2015-01-21 20:49:25 +01:00
|
|
|
http://docs.silverstripe.org/en/getting_started/environment_management/
|
2013-05-30 06:49:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
ENVCONTENT;
|
|
|
|
exit(1);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
DB::connect($databaseConfig);
|
|
|
|
|
2013-05-30 06:49:43 +02:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
// Get the request URL from the querystring arguments
|
2010-10-04 06:29:40 +02:00
|
|
|
$url = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : null;
|
|
|
|
if(!$url) {
|
2012-09-26 23:34:00 +02:00
|
|
|
echo 'Please specify an argument to cli-script.php/sake. For more information, visit'
|
2016-02-22 01:52:12 +01:00
|
|
|
. ' http://docs.silverstripe.org/en/developer_guides/cli' . "\n";
|
2010-10-04 06:29:40 +02:00
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
$_SERVER['REQUEST_URI'] = BASE_URL . '/' . $url;
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
// Direct away - this is the "main" function, that hands control to the apporopriate controller
|
2011-05-01 07:33:02 +02:00
|
|
|
DataModel::set_inst(new DataModel());
|
|
|
|
Director::direct($url, DataModel::inst());
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2012-02-12 21:22:11 +01:00
|
|
|
|