-
Notifications
You must be signed in to change notification settings - Fork 15
/
eep.php
executable file
·177 lines (159 loc) · 4.9 KB
/
eep.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/php
<?php
/*
EEP is a command line tool to support developers using ezpublish
Copyright © 2012 Mugo Web
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
*/
/**
* this switches the module it executes by "require_once"ing the file where
* the module is defined; this is done by naming the folder after the module
* and the main implementation file is "index.php"
*
* (for the eep PHP class, see /lib/eepHelpers.php :)
*
*/
mb_internal_encoding( "UTF-8" );
$pathParts = pathinfo( __FILE__ );
$eepPath = $pathParts["dirname"];
if( file_exists( getenv("HOME")."/eepSetting.php" ) )
{
require_once( getenv("HOME")."/eepSetting.php" );
}
elseif( file_exists( getenv("HOMEPATH")."/eepSetting.php" ) )
{
require_once( getenv("HOMEPATH")."/eepSetting.php" );
}
else
{
require_once( $eepPath . "/eepSetting.php" );
}
require_once( $eepPath . "/lib/eepHelpers.php" );
require_once( $eepPath . "/lib/eepCache.php" );
require_once( $eepPath . "/lib/AttributeFunctions.php" );
require_once( $eepPath . "/lib/eepLog.php" );
require_once( $eepPath . "/lib/eepValidate.php" );
$eepLogger = new eepLog( eepSetting::LogFolder, eepSetting::LogFile );
$eepCache = eepCache::getInstance();
$argModule = "help"; // default module in case no other is requested
if( isset($argv[1]) )
{
// expand the module name into it's full name if using an alias
$argv[1] = eep::expandAliases( $argv[1] );
$argModule = $argv[1];
}
$argCommand = "";
if( isset($argv[2]) )
{
// expand the function into it's full name if using an alias
$argv[2] = eep::expandAliases( $argv[2] );
$argCommand = $argv[2];
}
// make sure that the module is simple as a security precaution
$argModule = str_replace( array("/","\\",".",":"), "", $argModule );
// make sure that the module is one that is available
$availableModuleFolders = array();
$hDir = opendir( $eepPath . "/modules" );
$file = readdir( $hDir );
while( false != $file )
{
if( !in_array( $file , array(".", "..", ".svn") ))
{
$wholePath = $eepPath . "/modules/" . $file;
if( is_dir( $wholePath ) )
$availableModuleFolders[] = $file;
}
$file = readdir( $hDir );
}
if( !in_array( $argModule, $availableModuleFolders ) )
{
$msg = "Module is not supported. [" .$argModule. "]";
$eepLogger->Report( $msg, "fatal" );
}
sort( $availableModuleFolders );
// this is an expensive way to accomplish a global, and provides no advantage
// unless you can eventually implement a lazy write protocol to the cache
$eepCache->writetoCache( eepCache::misc_key_availablemodules, $availableModuleFolders );
// this is a special, hopefully unique, case where the module affects the
// startup
if( "use"==$argModule && "ezroot"==$argCommand )
{
$eepLogger->Report( "Reseting ezroot" );
}
else
{
$eZPublishRootPath = $eepCache->readFromCache( eepCache::use_key_ezroot );
if( isset( $eZPublishRootPath ) )
{
require $eZPublishRootPath.'/autoload.php';
chdir( $eZPublishRootPath );
}
else
{
// currently unused
//include_once( "ezc/Base/ezc_bootstrap.php" );
}
}
// if we are operating in the context of an ez publish, equivalently, if we are
// operating on an ez instance, we have to loadup the ez context
if( class_exists ( "eZScript", true ) )
{
// this isn't init'd in 4.6, or maybe it's something to do with cluster, anyway, initing it here prevents an ugly warning
$GLOBALS['eZContentClassAttributeCacheListFull'] = null;
$script = eZScript::instance
(
array
(
'description' => ( "eep (Ease eZ Publish) does some small tasks for you on the command line" )
, 'use-session' => false
, 'use-modules' => true
, 'use-extensions' => true
)
);
$script->initialize();
}
// do the main piece of work according to the index.php file in the requested folder
try
{
require_once( $eepPath . "/modules/" . $argModule . "/index.php" );
}
catch( Exception $e )
{
$msg = "An unhandled exception occured:\n";
$msg .= $e->getMessage() . "\n";
// make the exception legible
$details = $e->getTrace();
foreach( $details as $frame )
{
$msg .= " in " . $frame["file"];
$msg .= " on line: " . $frame["line"] . "\n";
$msg .= " " .$frame["function"]. "( ";
$space = "";
foreach( $frame["args"] as $paramSet )
{
if( is_array($paramSet) )
{
foreach( $paramSet as $aParam )
{
$msg .= $space . print_r( $aParam, true );
$space = " ";
}
}
else
{
$msg .= $space . $paramSet;
$space = " ";
}
}
$msg .= " )\n";
}
// and output it
$eepLogger->Report( $msg, "error" );
}
if( class_exists ( "eZScript", true ) )
{
$script->setExitCode( 1 );
$script->shutdown();
}
?>