Changeset 546 for trunk/lib


Ignore:
Timestamp:
Aug 27, 2015 2:35:55 AM (9 years ago)
Author:
anonymous
Message:

Detecting CLI also using php_sapi_name()

Location:
trunk/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/App.inc.php

    r536 r546  
    351351            // DB credentials for CLI scripts stored in a JSON file with read rights given only to the user who will be executing the scripts: -r--------
    352352            // But not if all DB credentials have been defined already by other means.
    353             if (defined('_CLI') && (!$this->getParam('db_server') || !$this->getParam('db_name') || !$this->getParam('db_user') || !$this->getParam('db_pass'))) {
     353            if (('cli' === php_sapi_name() || defined('_CLI')) && (!$this->getParam('db_server') || !$this->getParam('db_name') || !$this->getParam('db_user') || !$this->getParam('db_pass'))) {
    354354                if (false !== $db_auth_file = stream_resolve_include_path($this->getParam('db_auth_file'))) {
    355355                    if (is_readable($db_auth_file)) {
     
    386386
    387387        // Skip sessions if disabled or automatically skip if run in a CLI script.
    388         if (true === $this->getParam('enable_session') && !defined('_CLI')) {
     388        if (true === $this->getParam('enable_session') && !defined('_CLI') && 'cli' !== php_sapi_name()) {
    389389
    390390            // Session parameters.
     
    450450
    451451        // Character set. This should also be printed in the html header template.
    452         if (!defined('_CLI')) {
     452        if (!defined('_CLI') && 'cli' !== php_sapi_name()) {
    453453            if (!headers_sent($h_file, $h_line)) {
    454454                header('Content-type: text/html; charset=' . $this->getParam('character_set'));
     
    464464            $codebase_version = trim(file_get_contents($codebase_version_file));
    465465            $this->setParam(array('codebase_version' => $codebase_version));
    466             if (!defined('_CLI')) {
     466            if (!defined('_CLI') && 'cli' !== php_sapi_name()) {
    467467                if (!headers_sent($h_file, $h_line)) {
    468468                    header('X-Codebase-Version: ' . $codebase_version);
     
    487487            $this->setParam(array('site_version' => $site_version));
    488488        }
    489         if (!defined('_CLI') && $this->getParam('site_version')) {
     489        if (!defined('_CLI') && 'cli' !== php_sapi_name() && $this->getParam('site_version')) {
    490490            if (!headers_sent($h_file, $h_line)) {
    491491                header('X-Site-Version: ' . $site_version);
  • trunk/lib/DB.inc.php

    r532 r546  
    227227    {
    228228        if ($this->getParam('db_die_on_failure')) {
    229             if (!defined('_CLI')) {
     229            if (!defined('_CLI') && 'cli' !== php_sapi_name()) {
    230230                // For http requests, send a Service Unavailable header.
    231231                header(' ', true, 503);
     
    312312        // http://dev.mysql.com/doc/refman/5.0/en/gone-away.html
    313313        if (!mysql_ping($this->dbh)) {
    314             $app->logMsg(sprintf('MySQL ping failed; reconnecting
 ("%s")', truncate(trim($debugqry), 150)), LOG_NOTICE, __FILE__, __LINE__);
     314            $app->logMsg(sprintf('MySQL ping failed; reconnecting
 ("%s")', truncate(trim($debugqry), 150)), LOG_DEBUG, __FILE__, __LINE__);
    315315            $this->reconnect();
    316316        }
     
    323323            $app->logMsg(sprintf('MySQL error %s: %s in query: %s', mysql_errno($this->dbh), mysql_error($this->dbh), $debugqry), LOG_EMERG, __FILE__, __LINE__);
    324324            if ($this->getParam('db_debug')) {
    325                 if (!defined('_CLI')) {
     325                if (!defined('_CLI') && 'cli' !== php_sapi_name()) {
    326326                    echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>';
    327327                }
  • trunk/lib/Prefs.inc.php

    r541 r546  
    175175    {
    176176        // CLI scripts can't use prefs stored in HTTP-based protocols.
    177         if (defined('_CLI')
     177        if ((defined('_CLI') || 'cli' === php_sapi_name())
    178178        && isset($params['storagetype'])
    179179        && in_array($params['storagetype'], array('cookie', 'session'))) {
  • trunk/lib/Utilities.inc.php

    r545 r546  
    3737function dump($var, $display=false, $var_dump=false, $file='', $line='')
    3838{
    39     if (defined('_CLI')) {
     39    if (defined('_CLI') || 'cli' === php_sapi_name()) {
    4040        echo "DUMP FROM: $file $line\n";
    4141    } else {
     
    6060        }
    6161    }
    62     if (defined('_CLI')) {
     62    if (defined('_CLI') || 'cli' === php_sapi_name()) {
    6363        echo "\n";
    6464    } else {
Note: See TracChangeset for help on using the changeset viewer.