示例#1
0
}
$dir = dir($baseDir);
$currentVersionFile = $baseDir . DIRECTORY_SEPARATOR . 'current';
// this block executes the actual statements that were loaded from
// the schema file.
try {
    // let the user know whats going on (we are actually creating a
    // database here)
    if ('testing' != APPLICATION_ENV) {
        echo 'Writing Database for environment <' . APPLICATION_ENV . '> in (control-c to cancel): ' . PHP_EOL;
        for ($x = 3; $x > 0; $x--) {
            echo $x . "\r";
            sleep(1);
        }
    }
    $from = $cli->getOption('f');
    if (!$from) {
        $item = $db->config->findOne(array('_id' => 'version'));
        if ($item && isset($item['version'])) {
            $from = $item['version'];
        }
    }
    if (!$from) {
        if (file_exists($currentVersionFile)) {
            $from = file_get_contents($currentVersionFile);
        } else {
            $from = "0rev0";
        }
    }
    list($fromVer, $fromRev) = explode('rev', $from, 2);
    echo "Current version: " . $fromVer . "rev" . $fromRev . "\n";
#!/usr/bin/env php
<?php 
/**
 * Script for remove user session
 */
require_once realpath(dirname(__FILE__) . '/lib/Cli.php');
$cli = new Cli(array('userName|u=s' => 'User name of the session to delete ', 'debugMode|d-i' => 'Use 1 to enable debug mode (defaults to 0) '));
/**
 * @var MongoCollection
 */
$db = $cli->getResource('mongo');
$userName = $cli->getOption('u');
$debug = $cli->getOption('d');
try {
    if ($cli->getOption('u') === null) {
        throw new Exception("The 'userName' parameter is required");
    }
    if ($debug == 1) {
        $list = $db->session->find();
        foreach ($list as $session) {
            $s = $session['rawData']['Zend_Auth']['storage']['username'];
            print_r($s . "\n");
        }
        echo "\n" . $db->session->count() . "\n";
    }
    $count = $db->session->count() . "\n";
    $remove = $db->session->remove(array("rawData.Zend_Auth.storage.username" => "{$userName}"));
    $count_after_remove = $db->session->count() . "\n";
    if ($count > $count_after_remove) {
        echo "Removed active session for '{$userName}' user. \n";
    } else {
#!/usr/bin/env php
<?php 
/**
 * Script for creating and loading database
 * Execute "php load.oracle.php --help" for help
 */
// Initialize the application path and autoloading
require_once 'lib/Cli.php';
$cli = new Cli(array('drop|d' => 'Drop database and data', 'file|f=s' => 'Load file'), false);
try {
    /**
     * @var MongoCollection
     */
    if ($cli->getOption('e') === null) {
        throw new Exception('Need environment param');
    }
    global $db;
    global $drop;
    $db = $cli->getResource('mongo');
    $cli->getResource('cachemanager');
    // let the user know whats going on (we are actually creating a
    // database here)
    if ('testing' != APPLICATION_ENV) {
        echo 'Writing Database for environment <' . APPLICATION_ENV . '> in (control-c to cancel): ' . PHP_EOL;
        for ($x = 3; $x > 0; $x--) {
            echo $x . "\r";
            sleep(1);
        }
    }
    $env = $cli->getOption('e');
    $yamlFile = $cli->getOption('f');
#!/usr/bin/env php
<?php 
use Application\Service\OrgService;
use Application\Service\UserService;
use Application\Model\Organization\OrgCustomerModel;
use Application\Model\Validate\Organization\OrgParamMatchRegex;
/**
 * Script for delete Orgs
 */
require_once 'lib/Cli.php';
$cli = new Cli(array('filter|f-s' => 'organization key=value params to filter-out to delete several filters can be added in the form [key=value&key=value,...]', 'type|t-s' => 'organization type to delete'), false);
try {
    if ($cli->getOption('e') === null) {
        throw new Exception('Need environment param');
    }
    if ($cli->getOption('f') === null) {
        throw new Exception('Need organization name param');
    }
    //service instantation;
    $orgService = OrgService::getInstance();
    $orgFilterString = $cli->getOption('f');
    //this option can be included on filters too
    $orgType = $cli->getOption('t') ?: 'customer';
    parse_str($orgFilterString, $params);
    $params += array('type' => $orgType);
    /**
     * @var $filterList App_ListFilter
     */
    $filterList = $orgService->buildFilterList($params);
    if (!$filterList->filterCount()) {
        foreach ($params as $key => $value) {
#!/usr/bin/env php
<?php 
/**
 * Script to upgrade tariff templates
 */
require_once realpath(dirname(__FILE__) . '/lib/Cli.php');
$cli = new Cli(array('file|f=s' => 'Path to zone upgrading file. REQUIRED', 'zoneNamesfile|n=s' => 'Path to zone names file.', 'orgId|o=s' => 'Organization where upgrade tariff templates. If it is not defined it will try to use the name of file as orgId', 'separator|s=s' => "Separator of file data. Defautl \"\t\" [TAB]"));
try {
    $logs = array();
    App_MigrationTool_TemplatesTo20_ServiceTariffUtils::performUpgrade($cli->getOption('o'), $cli->getOption('f'), $cli->getOption('n'), $cli->getOption('s'), $logs);
    foreach ($logs as $line) {
        echo $line . "\n";
    }
} catch (Exception $e) {
    echo 'AN ERROR HAS OCCURRED:' . PHP_EOL;
    echo $e->getMessage() . PHP_EOL;
    foreach ($logs as $line) {
        echo $line . "\n";
    }
    exit(1);
}
// generally speaking, this script will be run from the command line
exit(0);
示例#6
0
#!/usr/bin/env php
<?php 
/**
 * Script
 */
require_once realpath(dirname(__FILE__) . '/lib/Cli.php');
$cli = new Cli(array('namespace|n=s' => "Update a namespace. [REQUIRED]", 'path|p-s' => "Define acl files base path. Default: /data/acl/build", 'no-resources|r' => "Avoid backup resources document."));
define("DEFAULT_ACL_BASEPATH", realpath(APPLICATION_PATH . '/../data/acl/build'));
try {
    /**
     * @var MongoCollection
     */
    $db = $cli->getResource('mongo');
    $env = $cli->getOption('e');
    $basepath = rtrim($cli->getOption('p') ?: DEFAULT_ACL_BASEPATH, DIRECTORY_SEPARATOR);
    $namespace = $cli->getOption('n');
    if (!($namespace = $cli->getOption('n'))) {
        echo "Namespace is requiered";
        exit(1);
    }
    $noResources = $cli->getOption('r') ? true : false;
    acl2Json($db, $namespace, $basepath, $noResources);
    //create JSON file from acl_portal collection
} catch (Exception $e) {
    echo "Error:\n";
    echo get_class($e) . ": " . $e->getMessage() . "\n";
    echo $e->getTraceAsString();
    exit(100);
}
function acl2Json($db, $ns, $basepath, $noResources = False)
{
#!/usr/bin/env php
<?php 
/**
 * Script for delete test org by the name
 */
require_once realpath(dirname(__FILE__) . '/lib/Cli.php');
$cli = new Cli(array('field|f-s' => 'db field (name  by default)', 'type|t-s' => 'Organization name for delete (no organization for delete  by default)', 'drop|d' => 'Drop database and data'));
// Initialize values based on presence or absence of CLI options
$field = $cli->getOption('f');
$name = $cli->getOption('t');
try {
    if ($cli->getOption('t') === null) {
        throw new Exception('Need organization name param');
    }
    if ($cli->getOption('f') === null) {
        $field = 'name';
    }
    /**
     * @var MongoCollection
     */
    $db = $cli->getResource('mongo');
    $count = $db->org_mock->count();
    $res = $db->org_mock->remove(array("{$field}" => "{$name}"));
    echo "removing org " . $name . " \n";
    $dcount = $db->org_mock->count();
    if ($count == $dcount) {
        echo "not exists an organization with " . $field . " = " . $name . " \n";
    } else {
        echo "removed Organitzation with " . $field . " = " . $name . " \n";
        $cacheManager = $cli->getResource('cachemanager');
        $cache = $cacheManager->getCache('memcached');
#!/usr/bin/env php
<?php 
use Core\Service\Transport\PopboxService;
use Core\Model\WatcherModel;
use Core\Service\WatcherService;
use Core\Model\EventModel;
use Application\Exceptions\InvalidArgumentException;
require_once realpath(dirname(__FILE__) . '/lib/Cli.php');
/**
 * Script
 */
$cli = new Cli(array('file|f-s' => "Json file for event.", 'cacheId|c-s' => "CacheId of event.", 'scopes|s=s' => "Coma separated scopes", 'low|l' => "Mark as priority low. If it isn't send it use high priority."));
try {
    if ($file = $cli->getOption('f')) {
        if (!file_exists($file)) {
            throw new InvalidArgumentException("File doesn't exist");
        }
        $json = file_get_contents($file);
        unlink($file);
        $data = Zend_Json::decode($json);
        $event = new EventModel($data);
    } else {
        if (!($cacheId = $cli->getOption('c')) || !($event = \App::cache()->load($cacheId))) {
            throw new InvalidArgumentException("File or cacheId valid is required");
        }
    }
    $scopes = explode(',', $cli->getOption('s'));
    $priority = $cli->getOption('l') ? WatcherModel::PRIORITY_HIGH : WatcherModel::PRIORITY_LOW;
    PopboxService::getInstance()->sendNotification($scopes, $event, $priority);
    //create JSON file from acl_portal collection
} catch (Exception $e) {
示例#9
0
<?php 
/**
 * Script for remove user session
 */
require_once realpath(dirname(__FILE__) . '/lib/Cli.php');
$cli = new Cli(array('drop|d' => "Remove current data."), false);
if ($cli->getApplication() == null) {
    exit(1);
}
/**
 * @var MongoCollection
 */
$db = $cli->getResource('mongo');
define("DEFAULT_ACL_BASEPATH", realpath(APPLICATION_PATH . '/../data/acl'));
try {
    $env = $cli->getOption('e');
    $drop = $cli->getOption('d') ? true : false;
    $f = file_get_contents(DEFAULT_ACL_BASEPATH . "/build/acl_out.json", 'r');
    if (!$f) {
        throw new Exception("Error to load file \n");
    }
    //decoding json file
    $json_a = Zend_Json_Decoder::decode($f);
    if ($drop) {
        echo "\nDrop acl_portal from " . $env . " env \n";
        $db->acl_portal->drop();
    }
    foreach ($json_a as $element) {
        $db->acl_portal->insert($element);
    }
    \App::cache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('Namespace'));
示例#10
0
#!/usr/bin/env php
<?php 
use Application\Service\OrgService;
use Application\Service\UserService;
use Application\Model\Organization\OrgCustomerModel;
/**
 * Script for delete Orgs
 */
require_once 'lib/Cli.php';
$cli = new Cli(array('orgId|o=s' => 'Org id to delete '), false);
try {
    if ($cli->getOption('e') === null) {
        throw new Exception('Need environment param');
    }
    if ($cli->getOption('o') === null) {
        throw new Exception('Need organization id param');
    }
    $orgId = $cli->getOption('o');
    $orgService = OrgService::getInstance();
    //removing org
    Application\Model\Mapper\ProtoAbstractMapper::$organizationId = $orgId;
    $org = $orgService->load($orgId);
    if ($org != null) {
        App::getOrgUserLogged($org);
        try {
            $orgService->delete($org->getId());
            echo "The organization with Id {$orgId} has been deleted \n";
        } catch (Exception $e) {
            echo 'AN ERROR HAS OCCURRED:' . PHP_EOL;
            echo $e->getMessage() . PHP_EOL;
            \App::log()->warn($e);
示例#11
0
#!/usr/bin/env php
<?php 
use Application\Exceptions\InvalidArgumentException;
require_once realpath(dirname(__FILE__) . '/lib/Cli.php');
define("DEFAULT_ACL_BASEPATH", realpath(APPLICATION_PATH . '/../data/acl'));
/**
 * Script
 */
$cli = new Cli(array('namespace|n-s' => "Update a namespace. Default: all", 'drop|d' => "Remove current data.", 'path|p-s' => "Define acl files base path. Default: " . DEFAULT_ACL_BASEPATH, 'format|f-s' => "Acl format: yaml, oldIni, ini or json. Default: yaml" . DEFAULT_ACL_BASEPATH, 'extra-prefix|x-s' => "Define prefix for extra files. Default: empty."));
try {
    /**
     * @var MongoCollection
     */
    $db = $cli->getResource('mongo');
    $env = $cli->getOption('e');
    $drop = $cli->getOption('d') ? true : false;
    $basepath = rtrim($cli->getOption('p') ?: DEFAULT_ACL_BASEPATH, DIRECTORY_SEPARATOR);
    $extraSubdir = $cli->getOption('x') ?: '';
    $format = $cli->getOption('f') ?: 'yaml';
    $namespaces = findNamespaces($basepath, $extraSubdir, $format);
    if (!($namespace = $cli->getOption('n')) || $namespace == 'all') {
        foreach ($namespaces as $ns => $files) {
            loadAcl($files, $ns, $format, $drop);
        }
    } else {
        if (isset($namespaces[$namespace])) {
            loadAcl($namespaces[$namespace], $namespace, $format, $drop);
        } else {
            echo "Namespace {$namespace} does not exist";
        }
    }
#!/usr/bin/env php
<?php 
use Core\Service\WatcherService;
use Core\Model\EventModel;
use Application\Exceptions\InvalidArgumentException;
require_once realpath(dirname(__FILE__) . '/lib/Cli.php');
define("DEFAULT_ACL_BASEPATH", realpath(APPLICATION_PATH . '/../data/acl'));
/**
 * Script
 */
$cli = new Cli(array('file|f-s' => "Json file for event.", 'cacheId|c-s' => "CacheId of event."));
try {
    if ($file = $cli->getOption('f')) {
        if (!file_exists($file)) {
            throw new InvalidArgumentException("File doesn't exist");
        }
        $json = file_get_contents($file);
        unlink($file);
        $data = Zend_Json::decode($json);
        $event = new EventModel($data);
    } else {
        if (!($cacheId = $cli->getOption('c')) || !($event = \App::cache()->load($cacheId))) {
            throw new InvalidArgumentException("File or cacheId valid is required");
        }
    }
    WatcherService::getInstance()->publishEventInternal($event);
    //create JSON file from acl_portal collection
} catch (Exception $e) {
    echo "Error:\n";
    echo get_class($e) . ": " . $e->getMessage() . "\n";
    echo $e->getTraceAsString();
示例#13
0
#!/usr/bin/env php
<?php 
/**
 * Script
 */
require_once realpath(dirname(__FILE__) . '/lib/Cli.php');
$cli = new Cli(array('namespace|n-s' => "Update a namespace. Default: all", 'path|p-s' => "Define acl files base path. Default: /data/acl/build", 'drop|d' => "Remove current data."));
define("DEFAULT_ACL_BASEPATH", realpath(APPLICATION_PATH . '/../data/acl/build'));
try {
    /**
     * @var MongoCollection
     */
    $db = $cli->getResource('mongo');
    $env = $cli->getOption('e');
    $basepath = rtrim($cli->getOption('p') ?: DEFAULT_ACL_BASEPATH, DIRECTORY_SEPARATOR);
    $namespace = $cli->getOption('n');
    $drop = $cli->getOption('d') ? true : false;
    $namespaces = getAclNamespaces($basepath);
    if (!($namespace = $cli->getOption('n')) || $namespace == 'all') {
        foreach ($namespaces as $ns => $file) {
            json2Acl($db, $ns, $file, $drop);
        }
    } else {
        if (isset($namespaces[$namespace])) {
            json2Acl($db, $namespace, $namespaces[$namespace], $drop);
        } else {
            echo "Namespace {$namespace} does not exist";
        }
    }
    //create JSON file from acl_portal collection
} catch (Exception $e) {
示例#14
0
#!/usr/bin/env php
<?php 
/**
 * Script
 */
require_once realpath(dirname(__FILE__) . '/lib/Cli.php');
$cli = new Cli(array('namespace|n-s' => "Update a namespace. Default: all", 'drop|d' => "Remove current data.", 'path|p-s' => "Define acl files base path. Default: /data/acl"));
define("DEFAULT_ACL_BASEPATH", realpath(APPLICATION_PATH . '/../data/acl'));
try {
    /**
     * @var MongoCollection
     */
    $db = $cli->getResource('mongo');
    $env = $cli->getOption('e');
    $drop = $cli->getOption('d') ? true : false;
    $basepath = $cli->getOption('p') ?: DEFAULT_ACL_BASEPATH;
    $namespaces = getAclNamespaces($basepath);
    if (!($namespace = $cli->getOption('n')) || $namespace == 'all') {
        if ($drop) {
            foreach ($namespaces as $ns => $file) {
                \App::cache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('Namespace'));
                dropNamespace($ns);
            }
        }
        foreach ($namespaces as $ns => $file) {
            \App::cache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('Namespace'));
            updateNamespace($ns, $file);
        }
    } else {
        if (isset($namespaces[$namespace])) {
            if ($drop) {