setCleanExit() static public méthode

*! Sets the clean exit flag to on, this notifies the exit handler that everything finished properly.
static public setCleanExit ( $hasCleanExit = true )
 public function __construct($theClass = '', $name = '')
 {
     parent::__construct($theClass, $name);
     if (!self::$script instanceof eZScript) {
         self::$script = eZScript::instance(array('description' => "eZ Publish Test Runner\n\nsets up an eZ Publish testing environment\n", 'use-session' => false, 'use-modules' => true, 'use-extensions' => true));
         // Override INI override folder from settings/override to
         // tests/settings to not read local override settings
         $ini = eZINI::instance();
         $ini->setOverrideDirs(array(array('tests/settings', true)), 'override');
         $ini->loadCache();
         // Be sure to have clean content language data
         eZContentLanguage::expireCache();
         self::$script->startup();
         self::$script->initialize();
         // Avoids Fatal error: eZ Publish did not finish its request if die() is used.
         eZExecution::setCleanExit();
     }
 }
function exitWithInternalError()
{
    header( $_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error' );
    eZExecution::cleanup();
    eZExecution::setCleanExit();
}
Exemple #3
0
    }
}
$cli = eZCLI::instance();
$script = eZScript::instance(array('description' => "eZ Publish Test Runner\n\n" . "sets up an eZ Publish testing environment" . "\n", 'use-session' => false, 'use-modules' => true, 'use-extensions' => true));
// Override INI override folder from settings/override to
// tests/settings to not read local override settings
$ini = eZINI::instance();
$ini->setOverrideDirs(array(array('tests/settings', true)), 'override');
$ini->loadCache();
// Be sure to have clean content language data
eZContentLanguage::expireCache();
$script->startup();
// $options = $script->getOptions();
$script->initialize();
// Avoids Fatal error: eZ Publish did not finish its request if die() is used.
eZExecution::setCleanExit();
$version = PHPUnit_Runner_Version::id();
if (version_compare($version, '3.5.0') == -1 && $version !== '@package_version@') {
    die("PHPUnit 3.5.0 (or later) is required to run this test suite.\n");
}
require_once 'PHP/CodeCoverage.php';
$codeCoverage = new PHP_CodeCoverage();
$codeCoverage->filter()->addFileToBlacklist(__FILE__, 'PHPUNIT');
//require_once 'bootstrap.php';
try {
    $runner = ezpTestRunner::instance();
    $runner->run($_SERVER['argv']);
} catch (Exception $e) {
    $cli->error($e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine());
    $cli->error($e->getTraceAsString());
}
 /**
  * Runs the shutdown process
  */
 protected function shutdown($reInitialize = true)
 {
     eZExecution::cleanup();
     eZExecution::setCleanExit();
     eZExpiryHandler::shutdown();
     if ($reInitialize) {
         $this->isInitialized = false;
     }
 }
Exemple #5
0
    /**
     * Installs the default Exception handler
     *
     * @params Exception the exception
     * @return void
     */
    static public function defaultExceptionHandler( Exception $e )
    {
        if( PHP_SAPI != 'cli' )
        {
            header( 'HTTP/1.x 500 Internal Server Error' );
            header( 'Content-Type: text/html' );

            echo "An unexpected error has occurred. Please contact the webmaster.<br />";

            if( eZDebug::isDebugEnabled() )
            {
                echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine();
            }
        }
        else
        {
            $cli = eZCLI::instance();
            $cli->error( "An unexpected error has occurred. Please contact the webmaster.");

            if( eZDebug::isDebugEnabled() )
            {
                $cli->error( $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() );
            }
        }

        eZLog::write( 'Unexpected error, the message was : ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine(), 'error.log' );

        eZExecution::cleanup();
        eZExecution::setCleanExit();
        exit( 1 );
    }
Exemple #6
0
 /**
  * This is called whenever an error occurs in one of the database handlers.
  *
  * If a transaction is active it will be invalidated as well.
  *
  * @access protected
  * @throws eZDBException
  */
 function reportError()
 {
     // If we have a running transaction we must mark as invalid
     // in which case a call to commit() will perform a rollback
     if ($this->TransactionCounter > 0) {
         $this->invalidateTransaction();
         // This is the unique ID for this incidence which will also be placed in the error logs.
         $transID = 'TRANSID-' . md5(time() . mt_rand());
         eZDebug::writeError('Transaction in progress failed due to DB error, transaction was rollbacked. Transaction ID is ' . $transID . '.', 'eZDBInterface::commit ' . $transID);
         $this->rollback();
         if ($this->errorHandling == eZDB::ERROR_HANDLING_EXCEPTIONS) {
             throw new eZDBException($this->ErrorMessage, $this->ErrorNumber);
         } else {
             // Stop execution immediately while allowing other systems (session etc.) to cleanup
             eZExecution::cleanup();
             eZExecution::setCleanExit();
             // Give some feedback, and also possibly show the debug output
             eZDebug::setHandleType(eZDebug::HANDLE_NONE);
             $ini = eZINI::instance();
             $adminEmail = $ini->variable('MailSettings', 'AdminEmail');
             if (!eZSys::isShellExecution()) {
                 if (!headers_sent()) {
                     header("HTTP/1.1 500 Internal Server Error");
                 }
                 $site = eZSys::serverVariable('HTTP_HOST');
                 $uri = eZSys::serverVariable('REQUEST_URI');
                 print "<div class=\"fatal-error\" style=\"";
                 print 'margin: 0.5em 0 1em 0; ' . 'padding: 0.25em 1em 0.75em 1em;' . 'border: 4px solid #000000;' . 'background-color: #f8f8f4;' . 'border-color: #f95038;" >';
                 print "<b>Fatal error</b>: A database transaction in eZ Publish failed.<br/>";
                 print "<p>";
                 print "The current execution was stopped to prevent further problems.<br/>\n" . "You should contact the <a href=\"mailto:{$adminEmail}?subject=Transaction failed on {$site} and URI {$uri} with ID {$transID}\">System Administrator</a> of this site with the information on this page.<br/>\n" . "The current transaction ID is <b>{$transID}</b> and has been logged.<br/>\n" . "Please include the transaction ID and the current URL when contacting the system administrator.<br/>\n";
                 print "</p>";
                 print "</div>";
                 $templateResult = null;
                 if (function_exists('eZDisplayResult')) {
                     eZDisplayResult($templateResult);
                 }
             } else {
                 fputs(STDERR, "Fatal error: A database transaction in eZ Publish failed.\n");
                 fputs(STDERR, "\n");
                 fputs(STDERR, "The current execution was stopped to prevent further problems.\n" . "You should contact the System Administrator ({$adminEmail}) of this site.\n" . "The current transaction ID is {$transID} and has been logged.\n" . "Please include the transaction ID and the name of the current script when contacting the system administrator.\n");
                 fputs(STDERR, "\n");
                 fputs(STDERR, eZDebug::printReport(false, false, true));
             }
             // PHP execution stops here
             exit(1);
         }
     }
 }
Exemple #7
0
 function shutdown($exitCode = false, $exitText = false)
 {
     $cli = eZCLI::instance();
     if (class_exists('eZDB') and eZDB::hasInstance()) {
         $db = eZDB::instance(false, array('show_errors' => false));
         // Perform transaction check
         $transactionCounterCheck = eZDB::checkTransactionCounter();
         if (isset($transactionCounterCheck['error'])) {
             $cli->error($transactionCounterCheck['error']);
         }
         if ($this->UseSession and $db->isConnected()) {
             eZUser::logoutCurrent();
             eZSession::remove();
         }
     }
     $webOutput = $cli->isWebOutput();
     if ($this->UseDebugOutput or eZDebug::isDebugEnabled()) {
         if ($this->DebugMessage) {
             fputs(STDERR, $this->DebugMessage);
         }
         fputs(STDERR, eZDebug::printReport(false, $webOutput, true, $this->AllowedDebugLevels, $this->UseDebugAccumulators, $this->UseDebugTimingPoints, $this->UseIncludeFiles));
     }
     eZExecution::cleanup();
     eZExecution::setCleanExit();
     $this->setIsInitialized(false);
     if ($exitCode !== false) {
         $this->ExitCode = $exitCode;
     }
     if ($this->ExitCode !== false) {
         if ($exitText !== false) {
             $cli->output($exitText);
         }
         exit($this->ExitCode);
     }
 }
Exemple #8
0
 /**
  * Handles an internal error.
  * If not using exceptions, will return an ezpKernelResult object with JSON encoded message.
  *
  * @param string $errorMessage
  * @param int $errorCode
  * @return ezpKernelResult
  *
  * @throws RuntimeException
  * @throws ezpAccessDenied
  *
  * @see setUseExceptions()
  */
 protected function exitWithInternalError($errorMessage, $errorCode = 500)
 {
     if (eZModule::$useExceptions) {
         switch ($errorCode) {
             case 403:
                 throw new ezpAccessDenied($errorMessage);
             case 500:
             default:
                 throw new RuntimeException($errorMessage, $errorCode);
         }
     } else {
         header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
         eZExecution::cleanup();
         eZExecution::setCleanExit();
         return new ezpKernelResult(json_encode(array('error' => $errorMessage, 'code' => $errorCode)));
     }
 }
 public static function soft_redirect( $string )
 {
     if ( !headers_sent() )
     {
         header('Location: '.$string);
         eZExecution::cleanup();
         eZExecution::setCleanExit();
         exit();
         return '';
     }
     return '';
 }