Merge branch 'performance'

Conflicts:
	workflow/public_html/sysGeneric.php
This commit is contained in:
Erik Amaru Ortiz
2014-03-12 18:33:22 -04:00
19 changed files with 2826 additions and 888 deletions

View File

@@ -1,6 +1,7 @@
<?php
global $RBAC;
$result = new StdClass();
switch ($_POST['action']) {
case 'countryList':

View File

@@ -1,107 +1,6 @@
<?php
namespace ProcessMaker\Util;
class Common
class Common extends \Maveriks\Util\Common
{
/**
* Recursive version of glob php standard function
*
* @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmail.com>
* @param string $pattern pattern for native glob function
* @param int|string $flags any valid flag for glob function
* @param bool $onlyFiles to filter return array with only matched files, or all matched results
* @return array array containing the recursive glob results
*
* Example:
*
* Common::rglob("/example/path/*");
*
* it will returns:
*
* Array
* (
* [0] => /example/path/README.txt
* [1] => /example/path/composer.json
* [4] => /example/path/one/one_text.txt
* [6] => /example/path/two/two_text.txt
* [7] => /example/path/two/two_one/two_one_text.txt
* [8] => /example/path/two/two_one/build.json
* )
*
* Example 2:
*
* Common::rglob("/example/path/*.json");
*
* It will returns:
*
* Array
* (
* [0] => /example/path/composer.json
* [1] => /example/path/two/two_one/build.json
* )
*/
public static function rglob($pattern, $flags = 0, $onlyFiles = false)
{
$singlePattern = basename($pattern);
if (strpos($singlePattern, "*") !== false) {
$path = rtrim(str_replace($singlePattern, "", $pattern), DIRECTORY_SEPARATOR);
} else {
$singlePattern = "";
$path = $pattern;
}
$files = glob("$path/$singlePattern", $flags);
$dirs = glob("$path/*", GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT);
foreach ($dirs as $dir) {
$files = array_merge($files, self::rglob("$dir/$singlePattern", $flags));
}
if ($onlyFiles) {
$files = array_filter($files, function($v) { return is_dir($v) ? false : true;});
}
return $files;
}
/**
* Returns the last version given a pattern of file name
*
* @param string $pattern a valid pattern for glob(...) native function
* @param int $flag php flags for glob(...) native function
* @return int|string
*
* Example:
* - Given the following files inside a directory:
* /example/path/myApplication-v1.tar
* /example/path/myApplication-v2.tar
* /example/path/myApplication-v3.tar
* /example/path/myApplication-v5.tar
* /example/path/myApplication-v7.tar
*
* $lastVer = ProcessMaker\Util\Common::getLastVersion("/example/path/myApplication-*.tar");
*
* It will returns: 7
*/
public static function getLastVersion($pattern, $flag = 0)
{
$files = glob($pattern, $flag);
$maxVersion = 0;
$pattern = str_replace("*", '([0-9\.]+)', basename($pattern));
foreach ($files as $file) {
$filename = basename($file);
if (preg_match('/'.$pattern.'/', $filename, $match)) {
if ($maxVersion < $match[1]) {
$maxVersion = $match[1];
}
}
}
return $maxVersion;
}
}

View File

@@ -8,66 +8,7 @@ namespace ProcessMaker\Util;
* @package ProcessMaker\Util
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com, erik@colosa.com>
*/
class Logger
class Logger extends \Maveriks\Util\Logger
{
private static $instance;
private $logFile;
private $fp;
protected function __construct()
{
$this->logFile = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'processmaker.log';
if (! file_exists($this->logFile)) {
if (! touch($this->logFile)) {
error_log("ProcessMaker Log file can't be created!");
}
chmod($this->logFile, 0777);
}
$this->fp = fopen($this->logFile, "a+");
}
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new Logger();
}
return self::$instance;
}
public function setLogLine()
{
$args = func_get_args();
$this->setLog(date('Y-m-d H:i:s') . " ");
foreach ($args as $str) {
$this->setLog((is_string($str) ? $str : var_export($str, true)) . PHP_EOL);
}
}
public function setLogInline()
{
$args = func_get_args();
$this->setLog(date('Y-m-d H:i:s') . " ");
foreach ($args as $str) {
$this->setLog((is_string($str) ? $str : var_export($str, true)) . " ");
}
}
public function setLog($str)
{
fwrite($this->fp, $str);
}
public static function log()
{
$me = Logger::getInstance();
$args = func_get_args();
call_user_func_array(array($me, 'setLogLine'), $args);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/*
* ProcessMaker Web Application Bootstrap
*/
try {
$rootDir = realpath(__DIR__ . "/../../") . DIRECTORY_SEPARATOR;
if (! is_dir($rootDir . 'vendor')) {
if (file_exists($rootDir . 'composer.phar')) {
throw new Exception(
"ERROR: Vendors are missing!" . PHP_EOL .
"Please execute the following command to install vendors:" .PHP_EOL.PHP_EOL.
"$>php composer.phar install"
);
} else {
throw new Exception(
"ERROR: Vendors are missing!" . PHP_EOL .
"Please execute the following commands to prepare/install vendors:" .PHP_EOL.PHP_EOL.
"$>curl -sS https://getcomposer.org/installer | php" . PHP_EOL .
"$>php composer.phar install"
);
}
}
if (! file_exists($rootDir . 'vendor' . DIRECTORY_SEPARATOR . "autoload.php")) {
throw new Exception(
"ERROR: Problems with Vendors!" . PHP_EOL .
"Please execute the following command to repair vendors:" .PHP_EOL.PHP_EOL.
"$>php composer.phar update"
);
}
require $rootDir . "framework/src/Maveriks/Util/ClassLoader.php";
$loader = Maveriks\Util\ClassLoader::getInstance();
$loader->add($rootDir . 'framework/src/', "Maveriks");
$loader->add($rootDir . 'workflow/engine/src/', "ProcessMaker");
$loader->add($rootDir . 'workflow/engine/src/');
$loader->add($rootDir . 'workflow/engine/classes/model/');
// and vendors to autoloader
$loader->add($rootDir . 'vendor/luracast/restler/vendor', "Luracast");
$loader->add($rootDir . 'vendor/bshaffer/oauth2-server-php/src/', "OAuth2");
$app = new Maveriks\WebApplication();
$app->setRootDir($rootDir);
$app->setRequestUri($_SERVER['REQUEST_URI']);
$stat = $app->route();
switch ($stat)
{
case Maveriks\WebApplication::RUNNING_WORKFLOW:
include "sysGeneric.php";
break;
case Maveriks\WebApplication::RUNNING_API:
$app->run(Maveriks\WebApplication::SERVICE_API);
break;
}
} catch (Exception $e) {
$view = new Maveriks\Pattern\Mvc\PhtmlView($rootDir . "framework/src/templates/Exception.phtml");
$view->set("message", $e->getMessage());
$view->set("exception", $e);
$response = new Maveriks\Http\Response($view->getOutput(), 503);
$response->send();
}

File diff suppressed because it is too large Load Diff