Exemplo n.º 1
0
/**
 * Запуск скрипта
 *
 * @param array &$ServiceManager объект сервис-менеджера
 */
function run(array &$ServiceManager)
{
    $shardsConfig = MysqlFactory\getShardsConfig(ServiceManager\getFactory($ServiceManager, 'Mysql'));
    // Заказчики
    $CustomerRepository =& ServiceManager\get($ServiceManager, 'CustomerRepository');
    foreach ($shardsConfig[CustomerRepository\SHARD_CONFIG] as $shardId => $_) {
        CustomerRepository\createShard($CustomerRepository, $shardId);
    }
    CustomerRepository\syncLastCustomerId($CustomerRepository, 0);
    // Два тестовых заказчика
    CustomerRepository\create($CustomerRepository, 'customer_1', 'Петров', '8anbAw4BbuoM');
    CustomerRepository\create($CustomerRepository, 'customer_2', 'Васечкин', 'GZx5ixNwYtos');
    // Заказы
    $OrderRepository =& ServiceManager\get($ServiceManager, 'OrderRepository');
    OrderRepository\createDatabaseAndTable($OrderRepository);
    // Два тестовых заказа
    OrderRepository\create($OrderRepository, 'text', 100);
    OrderRepository\create($OrderRepository, 'text2', 200);
    // Исполнители
    $ExecutorRepository =& ServiceManager\get($ServiceManager, 'ExecutorRepository');
    foreach ($shardsConfig[ExecutorRepository\SHARD_CONFIG] as $shardId => $_) {
        ExecutorRepository\createShard($ExecutorRepository, $shardId);
    }
    ExecutorRepository\syncLastExecutorId($ExecutorRepository, 0);
    // Два тестовых исполнителя
    ExecutorRepository\create($ExecutorRepository, 'executor_1', 'Иванов', 100, '3urvrPhNvEpZ');
    ExecutorRepository\create($ExecutorRepository, 'executor_2', 'Церетели', 200, 'ki22YIk1FR29');
}
Exemplo n.º 2
0
/**
 * Запуск скрипта
 *
 * @param array &$ServiceManager объект сервис-менеджера
 */
function run(array &$ServiceManager)
{
    $MysqlFactory =& ServiceManager\getFactory($ServiceManager, 'Mysql');
    $shardsConfig = MysqlFactory\getShardsConfig($MysqlFactory);
    // Заказчики
    $CustomerRepository =& ServiceManager\get($ServiceManager, 'CustomerRepository');
    $maxCustomerId = 1;
    foreach ($shardsConfig[CustomerRepository\SHARD_CONFIG] as $shardId => $_) {
        $Mysql = MysqlFactory\createShard($MysqlFactory, CustomerRepository\SHARD_CONFIG, $shardId);
        $data = Mysql\query($Mysql, 'SELECT * FROM ' . CustomerRepository\DATABASE_NAME . '.' . CustomerRepository\TABLE_NAME);
        while (($customerData = Mysql\fetchAssoc($Mysql, $data)) !== false) {
            $Customer =& Customer\unserializeFromMysql($customerData);
            CustomerRepository\saveToMemcached($CustomerRepository, $Customer);
            CustomerRepository\savePasswordHashToMemcached($CustomerRepository, $Customer, $customerData['password_hash']);
            $maxCustomerId = max($maxCustomerId, Customer\getId($Customer));
        }
    }
    CustomerRepository\syncLastCustomerId($CustomerRepository, $maxCustomerId);
    // Исполнители
    $ExecutorRepository =& ServiceManager\get($ServiceManager, 'ExecutorRepository');
    $maxExecutorId = 1;
    foreach ($shardsConfig[ExecutorRepository\SHARD_CONFIG] as $shardId => $_) {
        $Mysql =& MysqlFactory\createShard($MysqlFactory, ExecutorRepository\SHARD_CONFIG, $shardId);
        $data = Mysql\query($Mysql, 'SELECT * FROM ' . ExecutorRepository\TABLE_NAME . '.' . ExecutorRepository\TABLE_NAME);
        while (($executorData = Mysql\fetchAssoc($Mysql, $data)) !== false) {
            $Executor =& Executor\unserializeFromMysql($executorData);
            ExecutorRepository\saveLoginToMemcached($ExecutorRepository, Executor\getLogin($Executor), Executor\getId($Executor));
            ExecutorRepository\savePasswordHashToMemcached($ExecutorRepository, $Executor, $executorData['password_hash']);
            $maxExecutorId = max($maxExecutorId, Executor\getId($Executor));
        }
    }
    ExecutorRepository\syncLastExecutorId($ExecutorRepository, $maxExecutorId);
    // Заказы
    $OrderRepository =& ServiceManager\get($ServiceManager, 'OrderRepository');
    foreach (OrderRepository\fetchAll($OrderRepository) as $Order) {
        OrderRepository\savePriceToMemcached($OrderRepository, Order\getPrice($Order));
    }
}