Exemplo n.º 1
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));
    }
}
Exemplo n.º 2
0
/**
 * @param array &$ExecutorRepository объект репозитория исполнителя
 * @param string $login логин исполнителя
 *
 * @return &array|null объект исполнителя или null, если таковой не найден
 */
function &fetch(array &$ExecutorRepository, $login)
{
    $Memcached =& getMemcached($ExecutorRepository);
    $id = Memcached\get($Memcached, createMemcachedKeyForLogin($login));
    if ($id === false) {
        // нет такого исполнителя
        return null;
    }
    $id = (int) $id;
    $Mysql =& MysqlFactory\createShard(getMysqlFactory($ExecutorRepository), SHARD_CONFIG, getShardId($id));
    $result = Mysql\query($Mysql, 'SELECT id, fio, login, salary FROM ' . DATABASE_NAME . '.' . TABLE_NAME . ' WHERE id = ' . (int) $id);
    if (Mysql\numRows($result) == 0) {
        return null;
    }
    return Executor\unserializeFromMysql(Mysql\fetchAssoc($Mysql, $result));
}
Exemplo n.º 3
0
/**
 * Выборка заказов с id, не меньшим, чем указано
 *
 * @param array &$OrderRepository репозиторий заказа
 * @param int $idOffset id
 *
 * @return array объекты таких заказов
 */
function fetchWithIdOffset(array &$OrderRepository, $idOffset)
{
    $Mysql =& getMysql($OrderRepository);
    $Orders = [];
    $result = Mysql\query($Mysql, 'SELECT id, price, text FROM ' . DATABASE_NAME . '.' . TABLE_NAME . ' WHERE id >= ' . (int) $idOffset);
    while (($data = Mysql\fetchAssoc($Mysql, $result)) !== false) {
        $Orders[] =& Order\unserializeFromMysql($data);
    }
    return $Orders;
}