예제 #1
0
function queryCurrentRecord($describeSObjectResult, $id)
{
    $soql = "SELECT " . implode(",", fieldsToNameArray($describeSObjectResult->fields, false)) . " FROM " . $describeSObjectResult->name . " WHERE Id = '" . $id . "'";
    try {
        $queryResponse = WorkbenchContext::get()->getPartnerConnection()->queryAll($soql);
        if ($queryResponse->size == 1) {
            return new SObject($queryResponse->records[0]);
        }
    } catch (Exception $e) {
        workbenchLog(LOG_DEBUG, "queryCurrentRecord failed", $e->getMessage());
        return null;
    }
    return null;
}
예제 #2
0
 /**
  * Dequeues the next task for processing. Blocks until $timeout is reached.
  * Only to be called by CLI. Will error if called from a web process.
  *
  * @static
  * @return FutureTask
  */
 public static function dequeue($timeout)
 {
     verifyCallingFromCLI();
     $blpop = redis()->blpop(self::QUEUE, $timeout);
     if (isset($blpop[1])) {
         $task = crypto_unserialize($blpop[1]);
         if (!redis()->exists(FUTURE_LOCK . $task->asyncId)) {
             workbenchLog(LOG_INFO, "FutureTaskGC", array("async_id" => $task->asyncId, "request_id" => $task->requestId, "source" => get_class($task), "measure.async.gc.task" => 1 . "task"));
             throw new TimeoutException();
         }
         return $task;
     }
     throw new TimeoutException();
 }
예제 #3
0
</div>

</body>

<script type="text/javascript" src="<?php 
echo getPathToStaticResource('/script/wz_tooltip.js');
?>
"></script>

<?php 
if (isset($_REQUEST["footerScripts"])) {
    foreach ($_REQUEST["footerScripts"] as $script) {
        print $script . "\n";
    }
}
?>

</html>

<?php 
$peak = memory_get_peak_usage();
workbenchLog(LOG_INFO, "MemoryUsageCheck", array("measure.memory.peak" => $peak . "byte"));
if (WorkbenchContext::isEstablished() && $peak / toBytes(ini_get("memory_limit")) > 0.7) {
    WorkbenchContext::get()->clearCache();
    workbenchLog(LOG_INFO, "MemoryUsageCacheClear", array("measure.memory.cache_clear" => 1));
}
if (isset($GLOBALS['REDIS'])) {
    redis()->close();
}
//USAGE: debug($showSuperVars = true, $showSoap = true, $customName = null, $customValue = null)
debug(true, true, null, null);
        continue;
    }
    require_once "async/{$f}";
}
// block direct web access
if (php_sapi_name() != 'cli') {
    httpError(404, "Not Found");
}
$_SERVER['REMOTE_ADDR'] = 'CLI-' . getmypid();
$_SERVER['REQUEST_METHOD'] = 'ASYNC';
// future result gc
$frKeys = redis()->keys(FutureResult::RESULT . "*");
foreach ($frKeys as $frKey) {
    $asyncId = substr($frKey, strlen(FutureResult::RESULT));
    if (!redis()->exists(FUTURE_LOCK . $asyncId)) {
        redis()->del($frKey);
        workbenchLog(LOG_INFO, "FutureResultGC", array("async_id" => $asyncId, "request_id" => $task->requestId, "measure.async.gc.result" => 1 . "result"));
    }
}
workbenchLog(LOG_INFO, "FutureTaskQueueDepth", array("measure.async.queue_depth" => redis()->llen(FutureTask::QUEUE) . "task"));
while (true) {
    try {
        $job = FutureTask::dequeue(30);
        set_time_limit(WorkbenchConfig::get()->value('asyncTimeoutSeconds'));
        $job->execute();
    } catch (TimeoutException $e) {
        continue;
    }
    redis()->close();
    exit;
}
예제 #5
0
// OUT: tcp://host:port?auth=pass
if (strpos($sessionStore, "redis://") === 0) {
    $redisUrl = "tcp://" . parse_url($sessionStore, PHP_URL_HOST) . ":" . parse_url($sessionStore, PHP_URL_PORT);
    if (!is_array(parse_url($sessionStore, PHP_URL_PASS))) {
        $redisUrl .= "?auth=" . parse_url($sessionStore, PHP_URL_PASS);
    }
    ini_set("session.save_path", $redisUrl);
    ini_set("session.save_handler", "redis");
}
ini_set("session.cookie_httponly", "1");
session_start();
if (WorkbenchConfig::get()->value("redirectToHTTPS") && !usingSslFromUserToWorkbench()) {
    header("Location: " . "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    exit;
}
workbenchLog(LOG_INFO, "U", $logTail);
if (WorkbenchContext::isEstablished()) {
    WorkbenchContext::get()->beginRequestHook();
}
//clear ResultsWithData and retrievedZips from session unless downloading them
if (isset($_SESSION['resultsWithData']) && basename($_SERVER['PHP_SELF']) != 'downloadResultsWithData.php') {
    unset($_SESSION['resultsWithData']);
}
if (isset($_SESSION['retrievedZips']) && basename($_SERVER['PHP_SELF']) != 'metadataStatus.php') {
    unset($_SESSION['retrievedZips']);
}
if (WorkbenchContext::isEstablished() && isset($_REQUEST['clearCache'])) {
    WorkbenchContext::get()->clearCache();
    $cacheCleared = true;
}
// PATH_INFO can include malicious scripts and never used purposely in Workbench.
예제 #6
0
 /**
  * Dequeues the next task for processing. Blocks until $timeout is reached.
  * Only to be called by CLI. Will error if called from a web process.
  *
  * @static
  * @return FutureTask
  */
 public static function dequeue($timeout)
 {
     verifyCallingFromCLI();
     $blpop = redis()->blpop(self::QUEUE, $timeout);
     if (isset($blpop[1])) {
         $task = crypto_unserialize($blpop[1]);
         if (!redis()->exists(FUTURE_LOCK . $task->asyncId)) {
             workbenchLog(LOG_INFO, "FutureTaskGC", get_class($task) . "-" . $task->asyncId);
             throw new TimeoutException();
         }
         return $task;
     }
     throw new TimeoutException();
 }
예제 #7
0
function handleAllExceptionsInternal($e, $showHeadersFooters)
{
    $cause = $e;
    $fullMessage = "";
    while ($cause != null) {
        $fullMessage .= $cause->getCode() . ":" . $cause->getMessage() . "\n" . $e->getTraceAsString() . "\n";
        $cause = method_exists($cause, "getPrevious") ? $cause->getPrevious() : null;
    }
    if ($e instanceof WorkbenchAuthenticationException) {
        if (WorkbenchContext::isEstablished()) {
            WorkbenchContext::get()->release();
        }
        if (basename($_SERVER['PHP_SELF']) !== "logout.php") {
            if (!headers_sent()) {
                header("Location: logout.php?invalidateSession=1&message=" . urlencode($e->getMessage()));
            } else {
                $_REQUEST['invalidateSession'] = 1;
                $_REQUEST['message'] = $e->getMessage();
                include_once "logout.php";
            }
        }
        exit;
    }
    print "<p/>";
    if ($e instanceof WorkbenchHandledException) {
        if ($showHeadersFooters) {
            try {
                include_once 'header.php';
            } catch (Exception $e) {
            }
        }
        displayError($e->getMessage(), false, $showHeadersFooters);
    } else {
        if (strpos($e->getMessage(), "INVALID_SESSION_ID") === 0) {
            handleAllExceptions(new WorkbenchAuthenticationException("Your Salesforce session is invalid or has expired. Please login again."));
        }
        if (isKnownAuthenticationError($e->getMessage())) {
            handleAllExceptions(new WorkbenchAuthenticationException($e->getMessage()));
        }
        if ($showHeadersFooters) {
            try {
                include_once 'header.php';
            } catch (Exception $e) {
            }
        }
        workbenchLog(LOG_ERR, "E", "measure.exception=1 " . $fullMessage);
        displayError("UNKNOWN ERROR: " . $e->getMessage(), false, $showHeadersFooters);
    }
    exit;
}
예제 #8
0
// OUT: tcp://host:port?auth=pass
if (strpos($sessionStore, "redis://") === 0) {
    $redisUrl = "tcp://" . parse_url($sessionStore, PHP_URL_HOST) . ":" . parse_url($sessionStore, PHP_URL_PORT);
    if (!is_array(parse_url($sessionStore, PHP_URL_PASS))) {
        $redisUrl .= "?auth=" . parse_url($sessionStore, PHP_URL_PASS);
    }
    ini_set("session.save_path", $redisUrl);
    ini_set("session.save_handler", "redis");
}
ini_set("session.cookie_httponly", "1");
session_start();
if (WorkbenchConfig::get()->value("redirectToHTTPS") && !usingSslFromUserToWorkbench()) {
    header("Location: " . "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    exit;
}
workbenchLog(LOG_INFO, "U", $logMeasures);
if (WorkbenchContext::isEstablished()) {
    WorkbenchContext::get()->beginRequestHook();
}
//clear ResultsWithData and retrievedZips from session unless downloading them
if (isset($_SESSION['resultsWithData']) && basename($_SERVER['PHP_SELF']) != 'downloadResultsWithData.php') {
    unset($_SESSION['resultsWithData']);
}
if (isset($_SESSION['retrievedZips']) && basename($_SERVER['PHP_SELF']) != 'metadataStatus.php') {
    unset($_SESSION['retrievedZips']);
}
if (WorkbenchContext::isEstablished() && isset($_REQUEST['clearCache'])) {
    WorkbenchContext::get()->clearCache();
    $cacheCleared = true;
}
// PATH_INFO can include malicious scripts and never used purposely in Workbench.
예제 #9
0
        continue;
    }
    require_once "async/{$f}";
}
// block direct web access
if (php_sapi_name() != 'cli') {
    httpError(404, "Not Found");
}
$_SERVER['REMOTE_ADDR'] = 'CLI-' . getmypid();
$_SERVER['REQUEST_METHOD'] = 'ASYNC';
// future result gc
$frKeys = redis()->keys(FutureResult::RESULT . "*");
foreach ($frKeys as $frKey) {
    $asyncId = substr($frKey, strlen(FutureResult::RESULT));
    if (!redis()->exists(FUTURE_LOCK . $asyncId)) {
        redis()->del($frKey);
        workbenchLog(LOG_INFO, "FutureResultGC", $asyncId);
    }
}
workbenchLog(LOG_INFO, "FutureTaskQueueDepth", redis()->llen(FutureTask::QUEUE));
while (true) {
    try {
        $job = FutureTask::dequeue(30);
        set_time_limit(WorkbenchConfig::get()->value('asyncTimeoutSeconds'));
        $job->execute();
    } catch (TimeoutException $e) {
        continue;
    }
    redis()->close();
    exit;
}
 function __construct()
 {
     // initialize in case load issues
     $config = array();
     //load default config values
     require 'defaults.php';
     // load file-based config overrides
     if (is_file('config/overrides.php')) {
         /** @noinspection PhpIncludeInspection */
         require 'config/overrides.php';
     }
     // load legecy file-based config-overrides
     if (is_file('configOverrides.php')) {
         /** @noinspection PhpIncludeInspection */
         require 'configOverrides.php';
     }
     // unset from global namespace
     $this->config = $config;
     unset($config);
     // load environment variable based overrides
     $configNamespace = "forceworkbench";
     $configDelim = "__";
     foreach ($_ENV as $envKey => $envValue) {
         if (strpos($envKey, $configNamespace) !== 0) {
             continue;
         }
         $envKey = str_replace("___DOT___", ".", $envKey);
         $envKeyParts = explode($configDelim, $envKey);
         foreach ($envKeyParts as $keyPart) {
             if ($keyPart === $configNamespace) {
                 $point =& $this->config;
                 continue;
             }
             if (!isset($point[$keyPart])) {
                 $point[$keyPart] = "";
             }
             $point =& $point[$keyPart];
         }
         if (!isset($point) || is_array($point)) {
             workbenchLog(LOG_ERR, "Invalid location for {$envKey}");
             continue;
         }
         $point = $envValue === "false" ? false : $envValue;
     }
     foreach ($this->config as $configKey => $configValue) {
         // skip headers
         if (isset($configValue['isHeader'])) {
             continue;
         } else {
             if (isset($_COOKIE[$configKey])) {
                 // override the session value with that of the cookie
                 if ($configValue['overrideable']) {
                     $this->config[$configKey]['value'] = $_COOKIE[$configKey];
                 } else {
                     setcookie($configKey, NULL, time() - 3600);
                     $this->config[$configKey]['value'] = $configValue['default'];
                 }
             } else {
                 $this->config[$configKey]['value'] = $configValue['default'];
             }
         }
     }
     if ($this->config['callOptions_client']['default'] == 'WORKBENCH_DEFAULT' && !isset($_COOKIE['callOptions_client'])) {
         $this->config['callOptions_client']['value'] = getWorkbenchUserAgent();
     }
 }