/**
  * @param  Snapshot $snapshot
  * @return string
  */
 public function iniSettings(Snapshot $snapshot)
 {
     $result = '';
     foreach ($snapshot->iniSettings() as $key => $value) {
         $result .= sprintf('@ini_set(%s, %s);' . "\n", $this->exportVariable($key), $this->exportVariable($value));
     }
     return $result;
 }
Example #2
0
 public function testHtmlReport()
 {
     $snapshot = new Snapshot(__DIR__ . '/fakeproc');
     $html = $snapshot->htmlReport(false);
     $pos = strpos($html, '<table>');
     $this->assertNotFalse($pos);
     $pos = strpos($html, '</table>');
     $this->assertNotFalse($pos);
     $numTrOpen = substr_count($html, '<tr>');
     $numTrClose = substr_count($html, '</tr>');
     $this->assertEquals($numTrOpen, $numTrClose);
     $this->assertEquals($numTrOpen, 43);
     $numTdOpen = substr_count($html, '<td class="sysinfo_key">') + substr_count($html, '<td class="sysinfo_value">') + substr_count($html, '<td class="sysinfo_unit">');
     $numTdClose = substr_count($html, '</td>');
     $this->assertEquals($numTdOpen, $numTdClose);
     $htmlSummary = $snapshot->htmlReport(true);
     $pos = strpos($htmlSummary, '<p><strong>');
     $this->assertNotFalse($pos);
     $pos = strpos($htmlSummary, '</strong></p>');
     $this->assertNotFalse($pos);
 }
Example #3
0
 /**
  * @inheritdoc
  */
 protected function beforeAddLoadedItem(\Magento\Framework\Object $item)
 {
     $this->entitySnapshot->registerSnapshot($item);
     return $item;
 }
Example #4
0
 /**
  * @inheritdoc
  */
 protected function isModified(\Magento\Framework\Model\AbstractModel $object)
 {
     return $this->entitySnapshot->isModified($object);
 }
Example #5
0
 /**
  * Subtracts a snapshot from another one.
  *
  * The result will be a snapshot describing the execution metrics between the two snapshots
  * e.g. execution-time between two snapshots, memory-consumption from one snapshot to another etc.
  *
  * @param Snapshot $other
  *
  * @return Snapshot
  */
 public function diff(Snapshot $other)
 {
     return new self($this->_time - $other->getTime(), $this->_memoryUsage - $other->getMemoryUsage(), $this->_realMemoryUsage - $other->getRealMemoryUsage(), ($this->_memoryUsagePeak + $other->getMemoryUsagePeak()) / 2, ($this->_realMemoryUsagePeak + $other->getRealMemoryUsagePeak()) / 2);
 }
Example #6
0
#!/usr/bin/env php
<?php 
/*
 * Laconica - a distributed open-source microblogging tool
 * Copyright (C) 2009, Control Yourself, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
$helptext = <<<END_OF_SNAPSHOT_HELP
Batch script for sending snapshot information about this installation to devs.

END_OF_SNAPSHOT_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
Snapshot::check();
Example #7
0
 /**
  * Static function for reporting statistics
  *
  * This function checks whether it should report statistics, based on
  * the current configuation settings. If it should, it creates a new
  * Snapshot object, takes a snapshot, and reports it to headquarters.
  *
  * @return void
  */
 static function check()
 {
     switch (common_config('snapshot', 'run')) {
         case 'web':
             // skip if we're not running on the Web.
             if (!isset($_SERVER) || !array_key_exists('REQUEST_METHOD', $_SERVER)) {
                 break;
             }
             // Run once every frequency hits
             // XXX: do frequency by time (once a week, etc.) rather than
             // hits
             if (rand() % common_config('snapshot', 'frequency') == 0) {
                 $snapshot = new Snapshot();
                 $snapshot->take();
                 $snapshot->report();
             }
             break;
         case 'cron':
             // skip if we're running on the Web
             if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
                 break;
             }
             common_log(LOG_INFO, 'Running snapshot from cron job');
             // We're running from the command line; assume
             $snapshot = new Snapshot();
             $snapshot->take();
             common_log(LOG_INFO, count($snapshot->stats) . " statistics being uploaded.");
             $snapshot->report();
             break;
         case 'never':
             break;
         default:
             common_log(LOG_WARNING, "Unrecognized value for snapshot run config.");
     }
 }
Example #8
0
 /**
  * Implementation Create Backup functionality for Media
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return bool
  */
 public function create()
 {
     $this->_prepareIgnoreList();
     return parent::create();
 }
Example #9
0
 /**
  * Performs the benchmark.
  * At the start and at the end of the procedure call loop, it takes a snapshot
  * of PHP background data and returns the difference of both
  *
  * @param bool $withOutput If set to false, output is suppressed (var_dump, echo etc.) (Default: false)
  *
  * @return Snapshot
  */
 public function process($withOutput = false)
 {
     $it = $this->_iterationCount;
     if (!$withOutput) {
         ob_start();
     }
     $start = Snapshot::create();
     while ($it--) {
         call_user_func_array($this->_operation, $this->_args);
     }
     $end = Snapshot::create();
     if (!$withOutput) {
         ob_get_clean();
     }
     return $end->diff($start);
 }
Example #10
0
function main()
{
    // fake HTTP redirects using lighttpd's 404 redirects
    if (strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') !== false) {
        $_lighty_url = $base_url . $_SERVER['REQUEST_URI'];
        $_lighty_url = @parse_url($_lighty_url);
        if ($_lighty_url['path'] != '/index.php' && $_lighty_url['path'] != '/') {
            $_lighty_path = preg_replace('/^' . preg_quote(common_config('site', 'path')) . '\\//', '', substr($_lighty_url['path'], 1));
            $_SERVER['QUERY_STRING'] = 'p=' . $_lighty_path;
            if (isset($_lighty_url['query']) && $_lighty_url['query'] != '') {
                $_SERVER['QUERY_STRING'] .= '&' . $_lighty_url['query'];
                parse_str($_lighty_url['query'], $_lighty_query);
                foreach ($_lighty_query as $key => $val) {
                    $_GET[$key] = $_REQUEST[$key] = $val;
                }
            }
            $_GET['p'] = $_REQUEST['p'] = $_lighty_path;
        }
    }
    $_SERVER['REDIRECT_URL'] = preg_replace("/\\?.+\$/", "", $_SERVER['REQUEST_URI']);
    // quick check for fancy URL auto-detection support in installer.
    if (isset($_SERVER['REDIRECT_URL']) && preg_replace("/^\\/\$/", "", dirname($_SERVER['REQUEST_URI'])) . '/check-fancy' === $_SERVER['REDIRECT_URL']) {
        die("Fancy URL support detection succeeded. We suggest you enable this to get fancy (pretty) URLs.");
    }
    global $user, $action;
    Snapshot::check();
    if (!_have_config()) {
        $msg = sprintf(_("No configuration file found. Try running " . "the installation program first."));
        $sac = new ServerErrorAction($msg);
        $sac->showPage();
        return;
    }
    // For database errors
    PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
    // Make sure RW database is setup
    setupRW();
    // XXX: we need a little more structure in this script
    // get and cache current user (may hit RW!)
    $user = common_current_user();
    // initialize language env
    common_init_language();
    $path = getPath($_REQUEST);
    $r = Router::get();
    $args = $r->map($path);
    if (!$args) {
        $cac = new ClientErrorAction(_('Unknown page'), 404);
        $cac->showPage();
        return;
    }
    $args = array_merge($args, $_REQUEST);
    Event::handle('ArgsInitialize', array(&$args));
    $action = $args['action'];
    if (!$action || !preg_match('/^[a-zA-Z0-9_-]*$/', $action)) {
        common_redirect(common_local_url('public'));
        return;
    }
    // If the site is private, and they're not on one of the "public"
    // parts of the site, redirect to login
    if (!$user && common_config('site', 'private') && !isLoginAction($action) && !preg_match('/rss$/', $action) && $action != 'robotstxt' && !preg_match('/^Api/', $action)) {
        // set returnto
        $rargs =& common_copy_args($args);
        unset($rargs['action']);
        if (common_config('site', 'fancy')) {
            unset($rargs['p']);
        }
        if (array_key_exists('submit', $rargs)) {
            unset($rargs['submit']);
        }
        foreach (array_keys($_COOKIE) as $cookie) {
            unset($rargs[$cookie]);
        }
        common_set_returnto(common_local_url($action, $rargs));
        common_redirect(common_local_url('login'));
        return;
    }
    $action_class = ucfirst($action) . 'Action';
    if (!class_exists($action_class)) {
        $cac = new ClientErrorAction(_('Unknown action'), 404);
        $cac->showPage();
    } else {
        $action_obj = new $action_class();
        checkMirror($action_obj, $args);
        try {
            if ($action_obj->prepare($args)) {
                $action_obj->handle($args);
            }
        } catch (ClientException $cex) {
            $cac = new ClientErrorAction($cex->getMessage(), $cex->getCode());
            $cac->showPage();
        } catch (ServerException $sex) {
            // snort snort guffaw
            $sac = new ServerErrorAction($sex->getMessage(), $sex->getCode(), $sex);
            $sac->showPage();
        } catch (Exception $ex) {
            $sac = new ServerErrorAction($ex->getMessage(), 500, $ex);
            $sac->showPage();
        }
    }
}
Example #11
0
 public static function import(array $data)
 {
     $document = self::create($data['name'], $data['creation_date']);
     $document->changeCategories($data['categories']);
     $data['snapshots'] = array_reverse($data['snapshots']);
     foreach ($data['snapshots'] as $snapshot) {
         Snapshot::create($document, $snapshot['data'], strtotime($snapshot['creation_date']));
     }
 }
Example #12
0
} else {
    $conn_asm = oci_connect(ASM_USER, ASM_PASSWORD, '//' . ASM_HOSTNAME . '/' . ASM_SERVICE, '', OCI_SYSASM);
    if ($conn_asm == FALSE) {
        $error->set_msg("Failed to connect to ASM.");
    }
    $error->check();
}


/***
**** Check if Database has been setup for Oracle Database Demonstration
***/

$role = new Role();
$resource = new Resource();
$snapshot = new Snapshot();

// Check if Role has been created.
$flag_role_required = FALSE;
$result = $role->exist($conn_db, CLOUD_USER);
if ($result == FALSE) {
    $flag_role_required = TRUE;
} 

// Check if Consumer Groups have been created.
$flag_consumer_group_required = FALSE;
foreach ($array_consumer_group as $consumer_group) {
    $result = $resource->exist_consumer_group($conn_db, $consumer_group);
    if ($result == FALSE) {
        $flag_consumer_group_required = TRUE;
    }
        $error->skip = TRUE;
    }
}

if ($error->skip == TRUE) {
    goto start_html;
}


/***
**** Check if Database has been setup for Oracle Database Demonstration
***/

$role = new Role();
$resource = new Resource();
$snapshot = new Snapshot();

// Check if Role has been created.
$result = $role->exist($conn_db, CLOUD_USER);
if ($result == FALSE) {
    echo "<div id='flag_role_required' style='display:none;'>TRUE</div>\n";
} 

// Check if Consumer Groups have been created.
foreach ($array_consumer_group as $consumer_group) {
    $result = $resource->exist_consumer_group($conn_db, $consumer_group);
    if ($result == FALSE) {
        echo "<div id='flag_consumer_group_required' style='display:none;'>TRUE</div>\n";
    }
}
Example #14
0
     break;
 case 'saveCategories':
     $document = Document::fromDatabase($_POST['documentID']);
     $document->changeCategories(json_decode(stripslashes($_POST['categories']), true));
     break;
 case 'getSnapshots':
     $document = Document::fromDatabase($_POST['documentID']);
     echo json_encode(Snapshot::getList($document));
     break;
 case 'saveSnapshot':
     $document = Document::fromDatabase($_POST['documentID']);
     Snapshot::create($document, json_decode(stripslashes($_POST['documentData']), true), $_POST['timestamp']);
     break;
 case 'loadSnapshot':
     $document = Document::fromDatabase($_POST['documentID']);
     echo json_encode(Snapshot::getData($document, $_POST['snapshotID']));
     break;
 case 'deleteDocument':
     $document = Document::fromDatabase($_POST['id']);
     $document->delete();
     break;
 case 'loadDocuments':
     echo json_encode(Document::getList(Document::FORMAT_JSON));
     break;
 case 'createDocument':
     $document = Document::create($_POST['name']);
     echo $document->getId();
     break;
 case 'renameDocument':
     $document = Document::fromDatabase($_POST['id']);
     $document->rename($_POST['newname']);
Example #15
0
 public function download($snapshotId)
 {
     $snapshot = Snapshot::find($snapshotId);
     $filename = explode('/', $snapshot->webpage->url);
     $filename = array_pop($filename);
     header("Content-type:application/pdf");
     header("Content-Disposition:inline;filename='{$filename}'");
     header('Content-Transfer-Encoding: binary');
     header('Accept-Ranges: bytes');
     echo $snapshot->binary;
     exit;
 }