public function saveLog($xml) { // !!! // @todo Вот не знаю стоит ли тут делать так, или все же легче вызвать self::initReqXml(); но там у нас сессия инициализируется $this->_clientXml = new DOMDocument(); libxml_use_internal_errors(true); if (!$this->_clientXml->loadXML($xml)) { $this->_debug = 1; $xe_levels = array(LIBXML_ERR_WARNING => 'WARNING', LIBXML_ERR_ERROR => 'ERROR', LIBXML_ERR_FATAL => 'FATAL'); foreach (libxml_get_errors() as $xe) { $err .= $xe_levels[$xe->level] . ": (line: {$xe->line}, column: {$xe->column}): {$xe->message}"; } libxml_clear_errors(); $this->error(EXTERNAL_ERR_WRONG_REQ, $err); } $ns_name = basename($this->_clientXml->documentElement->getAttribute('xmlns:f')); if ($ns_name == '') { $ns_name = basename($this->_clientXml->documentElement->getAttribute('xmlns:hh')); } else { $ns_name = 'freetray'; } if ($ns_name == '') { $ns_name = 'other'; } $log = new log("external/{$ns_name}-%d%m%Y.log"); $log->writeln('--------------' . getRemoteIP() . '--------------'); $log->writeln($xml); }
public function payment($sum) { // На бете альфе включаем дебаг режим if (!is_release()) { //$sum = 0.1;// @debug $this->api->setDebug(true); } $result = $this->api->requestPayment(round((double) $sum, 2), $this->account->id); if ($result['status'] == API_Webmoney::STATUS_SUCCESS) { $process = $this->api->processPayment($this->api->merchant_transaction_id, $result['processor_transaction_id']); switch ($process['status']) { case API_Webmoney::STATUS_PAYMENT_PROGRESS: case API_Webmoney::STATUS_PAYMENT_SUCCESS: // Зачисляем деньги на бете/альфе // if(!is_release()) { // $paymentDateTime = date('d.m.Y H:i'); // $orderNumber = rand(1, 99999999); // $descr = "WebMoney с кошелька {$this->data['wallet']} сумма - {$sum}, обработан {$paymentDateTime}, номер покупки - $orderNumber"; // // $this->account->deposit($op_id, $this->account->id, $sum, $descr, 3, $sum, 12); // } return true; break; case API_Webmoney::STATUS_PAYMENT_FAIL: ob_start(); var_dump($result); var_dump($process); $content = ob_get_clean(); $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n"); $this->log->write("Request:\n " . $this->api->last_request->getBody()); $this->log->write("Result:\n {$content}"); return false; break; // Отложить платеж на пол часа // @todo придумать как отложить запрос на потом //case API_Webmoney::STATUS_PAYMENT_PROCESS: // Отложить платеж на пол часа // @todo придумать как отложить запрос на потом //case API_Webmoney::STATUS_PAYMENT_PROCESS: default: return; break; } } else { ob_start(); var_dump($result); $content = ob_get_clean(); $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n"); $this->log->write("Request:\n " . $this->api->last_request->getBody()); $this->log->write("Result:\n {$content}"); return false; } }
/** * Берет список записей и генерирует документы */ public function cron() { $queue = $this->getList(); require_once ABS_PATH . '/classes/log.php'; $log = new log('docgen_cron/' . SERVER . '-%d%m%Y.log', 'a', "%d.%m.%Y %H:%M:%S: "); foreach ($queue as $item) { try { $docGenClass = $this->getClass($item['class_name'], $item['class_params']); $docGenClass->setData(mb_unserialize($item['fields'])); $docGenClass->setDocName($item['type'], $item['original_name']); $docGenClass->beforeGenerate(); if ($docGenClass->isExcel($item['type'])) { $ok = $docGenClass->generateExcel($item['type']); } else { $ok = $docGenClass->generate($item['type']); } if ($ok) { $this->removeItem($item['id']); } else { $this->incrementTry($item['id']); } } catch (Exception $e) { $log->writeln(sprintf("id = %s: %s", $item['id'], iconv('CP1251', 'UTF-8', $e->getMessage()))); $this->incrementTry($item['id']); } } }
/** * Пишет сообщение в лог. * @param string $msg сообщение. */ private function _log($msg) { if (!$this->log) { return; } $this->log->writeln($msg); }
private function _log($message, $type = 'info') { if (!$this->_log) { return; } $msg = date("Y-m-d H:i:s") . " [{$type}] " . $message; $this->_log->writeln($msg); }
/** * Берем таблицы, последний анализ, которых был ранее чем analyze_min_age секунд назад * или количество изменненных строк > analyze_changed_factor * кол-во строк. * Сначала идут по времени последнего анализа. * Вопрос в том, что если сработал обычный автовакуум, то в autovacuum_log статистика не поменяется, * т.е. не будет известно сколько строк в реальности изменилось с последнего анализа. * Решение: не принимать во внимание, т.е. просто соблюдаем условия выше. Может случиться "лишний" анализ, не беда. */ public function analyze($db_alias, $mode = self::MODE_ANALYZE) { $cfg = $this->_config[$mode]; $log = new log($cfg['log_file'], 'w'); // !!! SERVER добавить (для альфы/беты). $DB = new DB($db_alias); $log->linePrefix = $this->_config['log_line_prefix']; $log->writeln('Получаем список таблиц'); $last_av_col = 'COALESCE(maintenance.max(' . ($mode == self::MODE_ANALYZE ? 'pt.last_analyze, pt.last_autoanalyze, ' : '') . "pt.last_vacuum, pt.last_autovacuum), 'epoch')"; $sql = "\n WITH w_stat as (\n SELECT ts.*, pt.*, ts.relid IS NULL as _is_new, {$last_av_col} as _last_av\n FROM pg_stat_user_tables pt\n LEFT JOIN\n maintenance.table_stat ts\n ON ts.relid = pt.relid\n WHERE pt.schemaname = 'public'\n AND pt.n_live_tup + pt.n_dead_tup > 0\n )\n (\n (SELECT *, 0 as ord, 0.00 as ord2 FROM w_stat WHERE (_is_new OR _last_av + interval '?i seconds' <= now()))\n UNION ALL\n (SELECT *, 1, tup_factor FROM w_stat WHERE tup_factor >= ?f)\n )\n ORDER BY ord, ord2 DESC, _last_av\n "; $tbls = $DB->rows($sql, $cfg['min_age'], $cfg['changed_factor']); $acnt = 0; $log->writeln(count($tbls) . ' таблиц'); foreach ($tbls as $t) { if ($log->getTotalTime(null) >= $cfg['max_duration']) { $log->writeln('Время истекло.'); break; } $DB->query(($mode == self::MODE_VACUUM ? 'VACUUM ' : 'ANALYZE') . " VERBOSE {$t['relname']}"); $cmpls[(int) ($t['_is_new'] == 't')][] = $t['relid']; $log->writeln(pg_last_notice(DB::$connections[$db_alias])); ++$acnt; } // Обновляем статистику. if ($cmpls[0]) { $cols = $this->_mt_cols; unset($cols[0], $cols[1]); $lcols = implode(',', $cols); $rcols = 'pt.' . implode(', pt.', $cols); $sql = "UPDATE maintenance.table_stat ts SET ({$lcols}) = ({$rcols}) FROM pg_stat_user_tables pt WHERE pt.relid IN (?l) AND ts.relid = pt.relid"; $DB->query($sql, $cmpls[0]); } if ($cmpls[1]) { $cols = implode(',', $this->_mt_cols); $sql = "INSERT INTO maintenance.table_stat ({$cols}) SELECT {$cols} FROM pg_stat_user_tables WHERE relid IN (?l)"; $DB->query($sql, $cmpls[1]); } // Удаляем лишние таблицы, типа catalog_positions2 (создаются/удаляются автоматом) $DB->query('DELETE FROM maintenance.table_stat ts WHERE NOT EXISTS (SELECT 1 FROM pg_stat_user_tables WHERE relid = ts.relid)'); $log->writeln("Обработано {$acnt} таблиц"); }
/** * Копирует массив файлов из WebDav в локальную файловую систему * Формат входных данных array("remotepath" => "localpath"). * * @param type $filelist * * @return bool */ public function get_files($filelist) { foreach ($this->_wdcs as $wdc) { if ($ok = $this->_connect($wdc)) { $ok = $wdc->mget($filelist); } if (!$ok) { $filelist = implode(', ', array_map(function ($v, $k) { return sprintf('from:%s to:%s', $k, $v); }, $filelist, array_keys($filelist))); $this->_log->writeln("error: could not get files {$filelist}, server: {$wdc->_server}"); } else { return true; } } return false; }
/** * Парсим реестр и генерируем счет-фактуры. * * @param type $filename */ public function parseFile($filename) { //@todo: это не красиво :( ini_set('max_execution_time', 300); //ini_set('memory_limit', '512M'); $uri = WDCPREFIX_LOCAL . $this->path . $filename; $list = array(); $ids = array(); $handle = fopen($uri, 'r'); while (($data = fgetcsv($handle, 1000, ';')) !== false) { if ($data[0] == 'order_id' || count($data) != 7) { continue; } //order_id;sf_num;sf_date;sf_summa;pp_num;pp_date;pp_type $res = array('id' => $this->getOrderId($data[0]), 'sf_num' => $data[1], 'sf_date' => $data[2], 'sf_summa' => $data[3], 'pp_num' => $data[4], 'pp_date' => $data[5], 'pp_type' => $data[6]); $ids[] = $res['id']; $list[] = $res; } fclose($handle); if ($list) { $reserveModel = ReservesModelFactory::getInstance(ReservesModelFactory::TYPE_TSERVICE_ORDER); $empData = $reserveModel->getEmpByReserveIds($ids); foreach ($list as $key => $data) { if (!isset($empData[$data['id']])) { continue; } $data['employer']['login'] = $empData[$data['id']]['login']; $data['employer']['uid'] = $empData[$data['id']]['uid']; $reserveModel->getReserve($ids[$key]); $data['employer']['reqv'] = $reserveModel->getEmpReqv(); try { $doc = new DocGenReserves($data); $doc->generateFactura(); } catch (Exception $e) { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/log.php'; $log = new log('reserves_docs/' . SERVER . '-%d%m%Y.log', 'a', '%d.%m.%Y %H:%M:%S: '); $log->writeln(sprintf('Order Id = %s: %s', $data['id'], iconv('CP1251', 'UTF-8', $e->getMessage()))); } } } }
/** * Автооплата услуги * * @param $sum * @return bool|mixed */ public function payment($sum) { $this->createOrder($sum); $this->api->getAccessData('autopay'); $result = $this->api->register($sum, $this->orderNumber, $this->account->id); if ($result['orderId'] != '') { walletAlpha::updateOrder($this->orderNumber, array('order_id' => $result['orderId'], 'state' => walletAlpha::STATE_NEW)); $payment = $this->api->paymentOrderBinding($result['orderId']); switch ($payment['errorCode']) { case API_AlphaBank::STATUS_SUCCESS: $status = $this->api->getOrderStatus($result['orderId']); $update = array('pan' => $status['Pan'], 'expiration' => $status['expiration'], 'cardholder_name' => $status['cardholderName'], 'ip' => $status['Ip'], 'binding_id' => Wallet::des()->encrypt($status['bindingId'])); $update['state'] = $this->deposit($this->account, $this->account->id, $status, $this->data['wallet'], $this->orderNumber, $sum); $this->updateOrder($this->orderNumber, $update); break; default: // Ошибка оплаты ob_start(); var_dump($result); var_dump($payment); $content = ob_get_clean(); $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n"); $this->log->write("Request:\n " . $this->api->last_request->getBody()); $this->log->write("Result:\n {$content}"); return false; break; } } else { ob_start(); var_dump($result); $content = ob_get_clean(); $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n"); $this->log->write("Request:\n " . $this->api->last_request->getBody()); $this->log->write("Result:\n {$content}"); return false; //error } }
/** * @deprecated Не использовать. Выплата делается в очереди PGQ там же и повторяется * * Крон переодического опроса API сервиса выплат * по сделкам в статусе ожидания выплаты * * @todo: документация API рекомендует опрашивать с интервалом мах 30 минут * @todo: возможно не лучшее место для этого? * * @param type $limit - количество сделок обрабатываемых за запуск * @return int - количество успешно обработанных сделок */ public function cron($limit = 10) { return false; $reservesModel = new ReservesModel(); $reserveDataList = $reservesModel->getReservesWithStatusPayByService(ReservesModel::SUBSTATUS_INPROGRESS, $limit); $cnt = 0; if ($reserveDataList) { $log = new log('reserves_docs/' . SERVER . '-%d%m%Y.log', 'a', "%d.%m.%Y %H:%M:%S: "); foreach ($reserveDataList as $reserveData) { $reserveInstance = ReservesModelFactory::getInstance($reserveData['type']); $reserveInstance->setReserveData($reserveData); $status = $this->payout($reserveInstance, $reserveData['pay_type']); $is_done = $reserveInstance->changePayStatus($status); if ($is_done && $reserveInstance->isClosed()) { $cnt++; $orderData = array('id' => $reserveData['src_id'], 'reserve_data' => $reserveInstance->getReserveData(), 'reserve' => $reserveInstance, 'employer' => array('login' => $reserveData['emp_login'], 'email' => $reserveData['emp_email'])); try { $doc = new DocGenReserves($orderData); $doc->generateActServiceEmp(); $doc->generateAgentReport(); } catch (Exception $e) { $log->writeln(sprintf("Order Id = %s: %s", $orderData['id'], iconv('CP1251', 'UTF-8', $e->getMessage()))); } } } } return $cnt; }
public function process_event(&$event) { $message = false; $cid = (string) @$event->data['cid']; try { $options = array('cid' => $cid, 'sc' => 'start', 'cd1' => $cid); if (isset($event->data['uid']) && $event->data['uid'] > 0) { $options['cd5'] = $event->data['uid']; } unset($event->data['uid']); $ga = StatisticFactory::getInstance('GA', $options); switch ($event->type) { case 'service_payed': $is_emp = (bool) @$event->data['is_emp']; $label = (string) @$event->data['label']; $ammount = floatval(@$event->data['ammount']); $ga->serviceWasPayed($is_emp, $label, $ammount, $cid); break; case 'project_answer': $project_kind_ident = (string) @$event->data['project_kind_ident']; $offer_count = (int) @$event->data['offer_count']; $is_pro = (bool) @$event->data['is_pro']; $offer_id = @$event->data['offer_id']; $ga->projectAnwer($cid, $project_kind_ident, $offer_count, $is_pro); break; case 'newsletter_projects_open_hit': $type = (int) @$event->data['type']; $label = (string) @$event->data['label']; $timestamp = (int) @$event->data['timestamp']; if ($type == 1) { $ga->newsletterNewProjectsOpenHitEmp($label, $timestamp); } else { $ga->newsletterNewProjectsOpenHitFrl($label, $timestamp); } break; //Обрабатываем методы которые поддерживает $ga инстанс //Обычно это типовые методы типа GA::event //Обрабатываем методы которые поддерживает $ga инстанс //Обычно это типовые методы типа GA::event default: unset($event->data['cid']); $ga->call($event->type, $event->data); break; } //Запись событий в лог if (is_object($ga) && method_exists($ga, 'getLastRequest')) { require_once ABS_PATH . '/classes/log.php'; $log = new log('statistic/' . SERVER . '-%d%m%Y.log'); $suffix = ''; if (isset($offer_id) && !empty($offer_id)) { $suffix = " offer_id={$offer_id}"; } $log->writeln(date('d.m.Y H:i:s') . ' - ' . $ga->getLastRequest()->getBaseUrlWithQuery() . $suffix); } } catch (Exception $e) { $message = 'Ошибка: ' . $e->getMessage(); } if ($message) { $data = ''; foreach ($event->data as $key => $value) { $data .= $key . '=' . $value . '; '; } $log_message = sprintf(self::LOG_FORMAT, $event->type, $data, $message); $this->log->notice(iconv('CP1251', 'UTF-8', $log_message)); //Повторить через 60 сек //$event->retry_delay = 60; //return PGQ_EVENT_RETRY; } return PGQ_EVENT_OK; }
/** * @todo: рекомендуется не использовать замена см addServiceAndCheckout * * Создаем запись в "Списке услуг" * * @param int $op_code ИД операции по которой создаем запись (@see table op_codes) * @param int $auto Автопродление для этого типа услуг * @param bool $clean_queue Очистить очередь * * @return int Возвращает ИД созданной услуги */ public function create($op_code, $auto = 0, $clean_queue = true) { //Чистим корзину заказов if ($clean_queue) { $this->cancelAllNewAndReserved(); } //Эти приготовления делаются без учета скидки и //только потом она будет использована если имеется if (in_array($op_code, self::getOpcodesByAutopayed('pro'))) { // Определяем автоматическую подставку автопро если не пользовались услугами долгое время $this->loadMainData(); if (isset($this->list_types_services['notused']['pro'])) { $auto = 1; } } //Пробуем получить скидку $op_code = $this->getDiscountOpCode($op_code); //Подготовка к покупке $options = $this->prepareOperationCode($op_code); $log = new log('billing/create-' . SERVER . '-%d%m%Y.log', 'a', "%d.%m.%Y %H:%M:%S:\r\n"); $log->writeln("create order ({$op_code}, {$auto})"); $log->write("login:{$this->user['login']}, uid:{$this->user['uid']}, account:{$this->acc['id']}, acc_sum:{$this->acc['sum']}\r\n"); ob_start(); var_dump($options); $out = ob_get_clean(); $log->write($out); $log->write("\r\n--------------------\r\n\r\n"); if (empty($options)) { return false; } $data = array('uid' => $this->user['uid'], 'op_code' => $op_code, 'auto' => $auto == 1 ? true : false); $insert = array_merge($data, $options); return $this->_db->insert('bill_queue', $insert, 'id'); }
/** * Разрешить отправку сообщений. * * @global type $DB * * @param type $to_id * @param type $from_id * * @return bool */ public static function setIsAllowed($to_id, $from_id, $stop_check = false) { global $DB; if (!$stop_check && self::_isAllowed($to_id, $from_id)) { return true; } $DB->val(' INSERT INTO ' . self::TABLE_ALLOWED . ' (to_id, from_id) SELECT ?i, ?i WHERE NOT EXISTS(SELECT 1 FROM ' . self::TABLE_ALLOWED . ' WHERE to_id = ?i AND from_id = ?i LIMIT 1); ', $to_id, $from_id, $to_id, $from_id); $mem = new memBuff(); $cache_tag_key = sprintf(self::CACHE_TAG_IS_ALLOWED, $from_id); $mem->delete($cache_tag_key); if (is_beta()) { require_once ABS_PATH . '/classes/log.php'; $log = new log('debug/0029319-%d%m%Y.log'); $log->writeln('----- ' . date('d.m.Y H:i:s')); $log->writeln("to_id = {$to_id}, from_id = {$from_id}"); } }
/** * Возврат денежных средств. * * @global type $DB * * @param type $payment_id ИД операции в paymaster * * @return bool */ public function refund($payment_id = null, $stage = null, $debug = false) { global $DB; $log = new log('pmpay/refundPayments-%d%m%Y.log', 'a', '%d.%m.%Y %H:%M:%S : '); $log->writeln("payment_id = [{$payment_id}], stage = [{$stage}], debug = [{$debug}]"); if (!$payment_id) { return false; } require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/pmpay.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/exrates.php'; $pmpay = new pmpay(); // Возврат осуществляется только при резервировании через WMR $sql = 'SELECT * FROM sbr_stages_payouts WHERE stage_id = ?i AND user_id = ?i AND is_refund IS NULL;'; $row = $DB->row($sql, $stage->id, $stage->sbr->emp_id); // Возврат осуществляется только для работодателей if ($row) { if (DEBUG) { $log->writeln('debug_mode = ON'); $pmpay->setDebugUrl($GLOBALS['host'] . '/norisk2/admin/pm-server-test.php'); } $operation = (array) $pmpay->refundPayments($payment_id, $row['credit_sum']); if ($operation && $operation['Status'] != 'FAILURE' && $operation['ErrorCode'] == 0) { if ($operation['Status'] == 'EXECUTING' || $operation['Status'] == 'PENDING') { $update = array('is_refund' => false, 'refund_id' => $operation['RefundID']); $this->refundStatusUpdate($update, $row['id']); } elseif ($operation['Status'] == 'SUCCESS') { $update = array('is_refund' => true, 'refund_id' => $operation['RefundID'], 'completed' => 'NOW()'); $this->refundStatusUpdate($update, $row['id']); } else { $update = array('is_refund' => null, 'refund_id' => $operation['RefundID']); $this->refundStatusUpdate($update, $row['id']); } } } else { $log = new log('pmpay/refundPayments-%d%m%Y.log', 'a', '%d.%m.%Y %H:%M:%S : '); $log->writeln("Ошибка выдачи SQL -- [{$DB->sql}]."); } }
/** * Деструктор. Закрывает открытую транзакцию и записывает в файл(ы) debug информацию. * */ public function __destruct() { --self::$objects; if ($this->debugLog) { $log = new log("db/" . $this->alias . "/debug/" . $this->debug); for ($i = 0; $i < count($this->debugLog); $i++) { $log->writeln($this->debugLog[$i]['text']); } } $log = new log("db/" . $this->alias . '/' . date('Y-m-d') . ".log"); if ($this->log) { $log->writeln($this->log); } if ($this->_transaction) { $rollback = false; $xstat = pg_transaction_status($this->_transaction); $xcodes = array(PGSQL_TRANSACTION_UNKNOWN => 'PGSQL_TRANSACTION_UNKNOWN', PGSQL_TRANSACTION_IDLE => 'PGSQL_TRANSACTION_IDLE', PGSQL_TRANSACTION_INTRANS => 'PGSQL_TRANSACTION_INTRANS', PGSQL_TRANSACTION_INERROR => 'PGSQL_TRANSACTION_INERROR', PGSQL_TRANSACTION_ACTIVE => 'PGSQL_TRANSACTION_ACTIVE'); switch ($xstat) { case PGSQL_TRANSACTION_INTRANS: case PGSQL_TRANSACTION_INERROR: case PGSQL_TRANSACTION_ACTIVE: $rollback = true; break; } if ($rollback) { $err = "Transaction status is BAD and it rollbacked: {$xcodes[$xstat]}, name=" . $this->alias; $this->rollback(); } else { $err = "Transaction counter is BAD on DESTRUCT: status {$xcodes[$xstat]}"; $this->_transaction = NULL; } $this->err($err); } if (!self::$objects) { setLastUserAction(); if (DB::$_stby_log) { // можно убрать, отладочное. $stby_db = new DB('stat'); setlocale(LC_ALL, 'en_US.UTF-8'); foreach (DB::$_stby_log as $key => $val) { list($val['day'], $val['real_mask'], $val['opts']) = explode('=', $key); $sql = "\n UPDATE stby_log2\n SET master_cnt = master_cnt + ?i, standby_cnt = standby_cnt + ?i,\n master_time = master_time + interval ?, standby_time = standby_time + ?, ro_errors_cnt = ro_errors_cnt + ?i\n WHERE day = ? AND opts = ? AND real_mask = ?i\n "; $res = $stby_db->query($sql, (int) $val['master_cnt'], (int) $val['standby_cnt'], (double) $val['master_time'] . ' seconds', (double) $val['standby_time'] . ' seconds', (int) $val['ro_errors_cnt'], $val['day'], $val['opts'], (int) $val['real_mask']); if (!pg_affected_rows($res)) { $sql = "\n INSERT INTO stby_log2 (master_cnt, standby_cnt, master_time, standby_time, ro_errors_cnt, day, opts, real_mask)\n VALUES (?i, ?i, ?, ?, ?i, ?, ?, ?i)\n "; $stby_db->query($sql, (int) $val['master_cnt'], (int) $val['standby_cnt'], (double) $val['master_time'] . ' seconds', (double) $val['standby_time'] . ' seconds', (int) $val['ro_errors_cnt'], $val['day'], $val['opts'], (int) $val['real_mask']); } } } DB::$_stby_log = array(); } }
<?php ini_set('max_execution_time', 0); ini_set('memory_limit', '512M'); require_once 'classes/config.php'; require_once 'classes/log.php'; require_once 'classes/multi_log.php'; $log = new log('hourly/' . SERVER . '-%d%m%Y[%H].log', 'w'); $log->writeln('------------ BEGIN hourly (start time: ' . date('d.m.Y H:i:s') . ') -----'); require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/smail.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/contacts.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/messages.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/sitemap.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/CFile.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/users.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stats.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/hh.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/freelancer.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stat_collector.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/professions.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/payed.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/pay_place.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/rating.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/account.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/professions.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/maintenance.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/search_parser.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/project_exrates.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/projects.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/static_compress.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/blogs.php';
/** * Проверяет статусы выставленных счетов. Пополняет счет для оплаченных. * * @param string $error сюда пишет ошибку. * @return integer количество пополненных счетов; */ function checkBillsStatus(&$error = NULL) { $offset = 0; $limit = 300; $completed_cnt = 0; libxml_disable_entity_loader(); $error = NULL; $sql = 'SELECT * FROM qiwi_account OFFSET ' . $offset . ' LIMIT ' . $limit; if (!($res = $this->DB->query($sql)) || !pg_num_rows($res)) { return 0; } while (pg_num_rows($res)) { $curr_bills = array(); $xml = '<?xml version="1.0" encoding="' . $this->encode . '"?>' . '<request>' . '<protocol-version>4.00</protocol-version>' . '<request-type>33</request-type>' . '<extra name="password">' . $this->passwd . '</extra>' . '<terminal-id>' . $this->login . '</terminal-id>' . '<bills-list>'; while ($row = pg_fetch_assoc($res)) { $xml .= '<bill txn-id="' . $row['id'] . '" />'; $curr_bills[$row['id']] = $row; } $log = new log('qiwipay/qiwi-%d%m%Y.log'); $log->writeln(); $log->writeln(date('c')); $log->writeln('==============================='); $xml .= '</bills-list></request>'; $log->writeln($xml); $result = $this->_request($xml); $log->writeln($result); if (!$result || ($error = $this->_checkResultError($result))) { return 0; } $xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?>' . $result); $bills = array(); foreach ($xml->{'bills-list'}->children() as $bill) { $status = (string) $bill['status']; $id = (string) $bill['id']; switch ($status) { case self::STATUS_ACCEPTED: case self::STATUS_PROCESS: continue 2; case self::STATUS_TERMINAL_ERROR: case self::STATUS_EXPIRED: case self::STATUS_CANCELED: $this->deleteBill($error, $id); break; case self::STATUS_COMPLETED: $this->completeBill($error, $curr_bills[$id], $bill['sum']); if (!$error) { $completed_cnt++; } break; default: $this->updateBillStatus($error, $id, $status); break; } } $offset = $offset + $limit; $sql = 'SELECT * FROM qiwi_account OFFSET ' . $offset . ' LIMIT ' . $limit; $res = $this->DB->query($sql); } return $completed_cnt; }
/** * Вынесение решения арбитром * @param array $form * @return \xajaxResponse */ function reservesArbitrageApply($form) { $objResponse = new xajaxResponse(); $order_id = @$form['order_id']; $price_pay = (int) @$form['price']; //Сумма для выплаты исполнителю $allow_fb_frl = (bool) @$form['allow_fb_frl']; $allow_fb_emp = (bool) @$form['allow_fb_emp']; $orderModel = TServiceOrderModel::model(); $orderModel->attributes(array('is_adm' => hasPermissions('tservices'))); $order = $orderModel->getCard((int) $order_id, get_uid(false)); if (!$order) { return $objResponse; } $reservesArbitrage = new ReservesArbitrage(); $reservesArbitrage->db()->start(); try { if ($price_pay > $order['reserve_data']['price']) { $price_pay = $order['reserve_data']['price']; } $price_back = $order['reserve_data']['price'] - $price_pay; //запоминаем суммы, которые надо выплатить сторонам, закрываем арбитраж и заказ $ok = $reservesArbitrage->closeArbitrage($order['reserve_data'], array('price_pay' => $price_pay, 'price_back' => $price_back, 'allow_fb_frl' => $allow_fb_frl, 'allow_fb_emp' => $allow_fb_emp)); if ($ok) { $is_emp = true; //Закрываем заказ от лица заказчика $orderModel->changeStatus($order_id, 'close', $is_emp); //Отправляем уведомления $reservesSmail = new ReservesSmail(); $reservesSmail->onApplyArbitrage($order, $price_pay); $order = $orderModel->getOrderData(); //Новый статус отображаем без перезагрузки $order['reserve_data']['arbitrage_price'] = $price_pay; $order['reserve_data']['arbitrage_date_close'] = date('Y-m-d H:i:s'); //Так как мы в статусах используем обьект то обновляем его данные $order['reserve']->setReserveData($order['reserve_data']); //$order['status'] = TServiceOrderModel::STATUS_EMPCLOSE; //Генерируем документы try { $doc = new DocGenReserves($order); if ($price_pay > 0) { $doc->generateActCompletedFrl(); } $doc->generateArbitrageReport(); } catch (Exception $e) { require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/log.php'; $log = new log('reserves_docs/' . SERVER . '-%d%m%Y.log', 'a', "%d.%m.%Y %H:%M:%S: "); $log->writeln(sprintf("Order Id = %s: %s", $order['id'], iconv('CP1251', 'UTF-8', $e->getMessage()))); } $tservicesOrderHistory = new tservices_order_history($order_id); $tservicesOrderHistory->reserveArbitrageDecide($price_pay, $price_back); $tserviceOrderStatusWidget = new TServiceOrderStatus(); $tserviceOrderStatusWidget->setIsOwner(false); $tserviceOrderStatusWidget->setOrder($order); $tserviceOrderStatusWidget->init(); ob_start(); $tserviceOrderStatusWidget->run(); $sHtml = ob_get_contents(); ob_end_clean(); $objResponse->assign('tservices_order_status_' . $order_id, 'innerHTML', $sHtml); } } catch (Exception $e) { $reservesArbitrage->db()->rollback(); $sHtml = tservices_helper::getMessage($e->getMessage(), 'error'); $objResponse->call('TServices_Order.showBeforeStatus', $order_id, $sHtml); return $objResponse; } $reservesArbitrage->db()->commit(); $objResponse->call('TServices_Order.hideBeforeStatus', $order_id); return $objResponse; }
/** * Покупка списка услуг ожидающих оплаты * * @todo: рекомендуется не использовать данный метод * * @param integer $gid Ид пользователя * @param integer $op_code Ид услуги */ public function buyOrdersList($gid, $op_code, $login = "") { $log = new log("billing/deposit-" . SERVER . '-%d%m%Y.log', 'a', "%d.%m.%Y %H:%M:%S:\r\n"); $log->writeln("deposit: login:{$login}, uid:{$gid}, code:{$op_code}\r\n"); if (!$gid) { return false; } require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/billing.php'; session_start(); $this->GetInfo($gid); $ac_sum = $this->sum; $log->write("start account_sum:{$ac_sum}\r\n"); if (in_array($op_code, billing::$op_code_transfer_money)) { // Деньги поступают на счет смотрим что можно оплатить $bill = new billing($gid); $reserve_operations = $bill->getReserveOperationsByStatus(); if (!empty($reserve_operations)) { ob_start(); var_dump($reserve_operations); $out = ob_get_clean(); $log->write($out . "\r\n"); //$mail_reserved = array(); $reserved_ids = array_map(create_function('$array', 'return $array["id"];'), $reserve_operations); $bill->startReserved($reserved_ids); // Блокируем услуги для изменений foreach ($reserve_operations as $reserve) { //$ret[$reserve['id']] = $reserve; $log->write("reserve {$reserve['id']} : {$ac_sum} >= {$reserve['ammount']}\r\n"); //if($ac_sum >= $reserve['ammount']) { // Пытаемся оплатить список услуг //$mail_reserved[] = $reserve['id']; $bill->transaction = $bill->account->start_transaction($bill->user['uid'], 0); $success = $bill->completeOrders($reserve['id']); $log->write("{$reserve['id']} ({$reserve['ammount']}) : {$success}\r\n"); if ($success) { $bill->account->commit_transaction($bill->transaction, $bill->user['uid'], NULL); $ac_sum = $ac_sum - $reserve['ammount']; } $log->write("set account_sum: {$ac_sum}\r\n---\r\n"); //} } $bill->stopReserved($reserved_ids); // Разблокируем услуги для изменений $log->write("done\r\n---------------------------------\r\n\r\n"); /* require_once($_SERVER['DOCUMENT_ROOT'] . '/classes/smail.php'); if (substr($bill->user['subscr'], 15, 1) == 1) { //$smail = new smail(); //$smail->sendReservedOrders($ret, $mail_reserved); } */ } $_SESSION['ac_sum'] = $ac_sum; } }
/** * Проверка на наши запросы POST, GET защита от CSRF * */ function csrf_magic() { static $log; if (defined("NO_CSRF")) { return true; } // Не проеверяем если отключена проверка в скрипте if ($_POST['u_token_key'] != $_SESSION['rand']) { if (!$log) { require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/log.php"; $log = new log('csrf/' . SERVER . '-%d%m%Y.log', 'a', '%d.%m.%Y %H:%M:%S - ' . getRemoteIP() . ' "' . $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . '"' . ' "' . $_SERVER['HTTP_USER_AGENT'] . '"'); } $log->writeln(" post_key: {$_POST['u_token_key']}, session_key: {$_SESSION['rand']}"); $_POST = array(); $_REQUEST = array(); } }
/** * Формирует успешный ответ на платеж. * * @param integer $billnumber номер операции в системе Assist. * @param string $packetdate дата операции по Assist. */ function success($billnumber, $packetdate) { $ret = '<?xml version="1.0" encoding="UTF-8"?>' . '<pushpaymentresult firstcode="0" secondcode="0">' . '<order>' . '<billnumber>' . $billnumber . '</billnumber>' . '<packetdate>' . $packetdate . '</packetdate>' . '</order>' . '</pushpaymentresult>'; $this->log->writeln('ОК'); die($ret); }
/** * Оплачиваем услуг * * @param float $sum Сумма услуги * @return bool|mixed|null */ public function payment($sum) { // На бете альфе включаем дебаг режим if (!is_release()) { $this->api->setDebug(true); } $result = $this->api->requestPayment(round((double) $sum, 2), $this->account->id); if ($result['status'] == API_Yandex::STATUS_SUCCESS) { // не откуда взять csc // foreach($result['money_source'] as $name=>$value) { // // Первый доступный метод оплаты // if($value['allowed'] == true) { // $money_source = $name; // break; // } // } // Для беты сумму баланса не проверяем if (($result['balance'] > $sum || !is_release()) && $result['request_id'] != '') { $process = $this->api->processPayment($result['request_id']); switch ($process['status']) { case API_Yandex::STATUS_SUCCESS: // Зачисляем деньги на бете/альфе if (!is_release()) { $paymentDateTime = date('d.m.Y H:i'); $orderNumber = rand(1, 99999999); $descr = "ЯД с кошелька {$this->data['wallet']} сумма - {$sum}, обработан {$paymentDateTime}, номер покупки - {$orderNumber}"; $this->account->deposit($op_id, $this->account->id, $sum, $descr, 3, $sum, 12); } return true; break; case API_Yandex::STATUS_FAIL: ob_start(); var_dump($result); var_dump($process); $content = ob_get_clean(); $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n"); $this->log->write("Request:\n " . $this->api->last_request->getBody()); $this->log->write("Result:\n {$content}"); return false; break; // Отложить платеж на пол часа // @todo придумать как отложить запрос на потом // Отложить платеж на пол часа // @todo придумать как отложить запрос на потом case API_Yandex::STATUS_PROCESS: default: return null; break; } } else { ob_start(); var_dump($result); $content = ob_get_clean(); $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n"); $this->log->write("Request:\n " . $this->api->last_request->getBody()); $this->log->write("Result:\n {$content}"); return false; //error } } else { ob_start(); var_dump($result); $content = ob_get_clean(); $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n"); $this->log->write("Request:\n " . $this->api->last_request->getBody()); $this->log->write("Result:\n {$content}"); return false; } }
/** * Переносим все выбранные платные операции в черновики операций * * @param array $selected Платные операции */ public function transferPaidOptionsToDraft($selected) { // На всякий случай берем переносимые опции из базы чтобы не было подлогов $options = $this->getPaidOptionById($selected); $log = new log('wizard/transfer-' . SERVER . '-%d.log', 'a', '%d.%m.%Y %H:%M:%S : '); if ($options) { foreach ($options as $option) { $id = $this->createDraftAccountOperation($option); if ($id) { $delete[] = $id; } else { $log->writeln("Error transfer paid option to draft - user (" . wizard::getUserIDReg() . "|" . step_wizard::getWizardUserID() . ") - option #{$option['id']} (wizard_billing)"); } } return $delete; } return false; }
<?php define('NO_CSRF', 1); require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/stdf.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/yandex_kassa.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/log.php"; $yandex_kassa = new yandex_kassa(); $log = new log('ykassa/%d%m%Y.log'); $log->writeln('----- ' . date('d.m.Y H:i:s')); $log->writevar($_POST); $action = __paramInit('string', null, 'action'); //@todo: выставляем тестовый режим для валидации по IP //после тестирования резерва БС убрать /* $scid = __paramInit('string', null, 'scid'); $is_test = $scid == yandex_kassa::SCID_SBR_TEST; if($is_test) $yandex_kassa->setTest($is_test); */ $result = array(); if ($action == 'checkOrder') { $result = $yandex_kassa->order(false); } if ($action == 'paymentAviso') { $result = $yandex_kassa->order(true); } $log->writeln('----- ' . (isset($result['message']) ? $result['message'] : 'YES')); $log->writeln(); echo "<?xml version=\"1.0\" encoding=\"windows-1251\"?>"; ?> <<?php
<?php define('NO_CSRF', 1); require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stdf.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/platipotom.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/log.php'; $platipotom = new platipotom(); $log = new log('platipotom/%d%m%Y.log'); $log->writeln('----- ' . date('d.m.Y H:i:s')); $log->writevar($_GET); $result = $platipotom->order(); $log->writeln('----- ' . (isset($result['status']) && $result['status'] == 1 ? 'SUCCESS' : 'FAIL')); $log->writeln(); header('Content-Type: application/json'); echo json_encode($result);
/** * @param string $uri * @param string $params * @return OriginalServerResponse */ private function makePostCurlRequest($uri, $params) { $cmd = key($params); $params = current($params); $converter = new Array2XML(); $converter->setConvertFromEncoding('windows-1251'); $converter->setTopNodeName($cmd); $converter->importArray($params); $data = $converter->saveXml(); $crypt = $this->getCryptOption(); if ($crypt) { $cryptBlock = new CryptBlock($crypt); $encryptData = $cryptBlock->encrypt($data); } else { $encryptData = $data; } require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/log.php"; $log = new \log('reserves_payout/' . SERVER . '-%d%m%Y.log'); $log->writeln(PHP_EOL . PHP_EOL); $log->writeln('[' . date('d.m.Y H:i:s') . ']'); $log->writeln($data); $headers = $this->prepareRequestHeaders(); $curl = curl_init($uri); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); if ($crypt) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSLCERT, $crypt['encrypt_cert_path']); curl_setopt($curl, CURLOPT_SSLKEY, $crypt['private_key_path']); curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $crypt['passphrase']); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl, CURLOPT_TIMEOUT, 80); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $encryptData); //$this->writeMessageToLogFile($this->prepareLogMessage($uri, $params)); $responseRaw = curl_exec($curl); $errorCode = curl_errno($curl); $errorMessage = curl_error($curl); $responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); $responseHeaderSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $responseHeadersRaw = trim(substr($responseRaw, 0, $responseHeaderSize)); $responseBodyRaw = trim(substr($responseRaw, $responseHeaderSize)); curl_close($curl); if ($responseCode == 200) { if ($crypt && $cryptBlock->isReqDecrypt()) { $responseBodyRaw = $cryptBlock->decrypt($responseBodyRaw); } $log->writeln($responseBodyRaw); } /* $this->writeMessageToLogFile( $this->prepareLogMessageExtended($uri, $params, $responseCode, $errorCode, $errorMessage) ); */ $this->originalServerResponse = new OriginalServerResponse(); $this->originalServerResponse->setCode($responseCode); $this->originalServerResponse->setHeadersRaw($responseHeadersRaw); $this->originalServerResponse->setBodyRaw($responseBodyRaw); $this->originalServerResponse->setErrorCode($errorCode); $this->originalServerResponse->setErrorMessage($errorMessage); }
* пачами по 100 за запуск, можно увеличиваь если скрипт справл¤етс¤ */ $time_start = microtime(true); ini_set('display_errors', 1); error_reporting(E_ALL ^ E_NOTICE); ini_set('max_execution_time', 0); ini_set('memory_limit', '512M'); if (!isset($_SERVER['DOCUMENT_ROOT']) || !strlen($_SERVER['DOCUMENT_ROOT'])) { $_SERVER['DOCUMENT_ROOT'] = rtrim(realpath(pathinfo(__FILE__, PATHINFO_DIRNAME) . '/../../'), '/'); } require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/stdf.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/CFile.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/log.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/multi_log.php"; $log = new log('dav_move/' . SERVER . '-to_account-%d%m%Y.log'); $log->writeln('------------ BEGIN (start time: ' . date('d.m.Y H:i:s') . ') -----'); $list = $DB->rows("\n SELECT \n\tfl.*,\n\tu.login\n FROM account_attach AS aa\n INNER JOIN account AS a ON a.id = aa.account_id\n INNER JOIN users AS u ON u.uid = a.uid \n INNER JOIN file AS fl ON fl.id = aa.file_id\n WHERE EXISTS (\n SELECT 1 \n FROM file AS f \n WHERE \n f.id = aa.file_id \n AND (\n \tf.path NOT LIKE '%/attach/' \n \tAND f.path NOT LIKE '%/attach/finance_other/'\n \tAND f.path NOT LIKE '%/private/account/'\n \tAND f.path NOT LIKE '%/private/account/finance_other/'\n \t)\n ) \n \n --AND u.login IN('testuser4','vgavran')\n --AND u.last_time < '2015-03-01'\n \n LIMIT 200;\n"); $cnt = count($list); //print_r("Found {$cnt} files \n"); $log->writeln("Found {$cnt} files"); $users_links_ok = array(); $users_links_fail = array(); if ($list) { $cnt_succes = 0; //$cnt_path_fail = 0; $cnt_rename_fail = 0; foreach ($list as $file) { $cfile = new CFile(); $cfile->id = $file['id']; $cfile->name = $file['fname']; $cfile->path = $file['path'];
/** * Сборщик мусора, удаляем все кроме последней и предыдущей версии * запускается в 6 часов утра каждый день @see hourly.php * * @return boolean */ public function cleaner() { global $DB; $path_static = self::STATIC_WDPATH; $this->_log->writeln('garbage collecting...'); $dcnt = 0; $batches = $this->getBatchesInfo(); $cur_version = $batches['version']; if (!$cur_version) { $this->_log->writeln('failed: batch version is undefined'); return false; } $sql = "SELECT id, fname FROM file WHERE path = '{$path_static}/'"; if ($result = $DB->rows($sql)) { $prev_version = 0; foreach ($result as $key => $value) { $file_version = $this->parseFileName($value['fname'], 1); $result[$key]['version'] = $file_version; if ($file_version > $prev_version && $file_version < $cur_version) { $prev_version = $file_version; } } $cfile = new CFile(); foreach ($result as $value) { if ($value['version'] < $prev_version) { $dcnt++; $cfile->Delete($value['id']); } } } $this->_log->writeln("ok: {$dcnt} file(s) deleted"); }
<?php ini_set('max_execution_time', '0'); ini_set('memory_limit', '512M'); require_once '../classes/config.php'; require_once '../classes/log.php'; $log = new log('massend-test-' . SERVER . '-%d%m%Y[%H].log', 'w'); $log->writeln('------------ BEGIN hourly (start time: ' . date('d.m.Y H:i:s') . ') -----'); require_once '../classes/stdf.php'; require_once '../classes/spam.php'; $spam = new spam(); $log->TRACE($spam->frlLowFundsOffers2());
SELECT fro.src_id, array_agg(fro.doc_type)::int[] AS doc_types FROM file_reserves_order AS fro INNER JOIN reserves AS r ON r.src_id = fro.src_id WHERE r.status IN(20,30) GROUP BY fro.src_id HAVING array_agg(fro.doc_type)::int[] @> ARRAY[10,20,30,40,50,60] = false AND array_agg(fro.doc_type)::int[] @> ARRAY[10,20,30,40,50,60,70] = false AND array_agg(fro.doc_type)::int[] @> ARRAY[20,30,40,50,60,70] = false LIMIT 10; '); if ($rows) { $log->writeln(sprintf('BEGIN hourly for %s reserves', count($rows))); $cnt = 0; foreach ($rows as $row) { $order_id = $row['src_id']; $doc_types = $DB->array_to_php2($row['doc_types']); $log->writeln(sprintf('Order Id = %s', $order_id)); try { $orderModel = TServiceOrderModel::model(); $orderModel->attributes(array('is_adm' => true)); $orderData = $orderModel->getCard($order_id, 0); if (!$orderData || !$orderModel->isStatusEmpClose() || !$orderModel->isReserve()) { $log->writeln('Not isStatusEmpClose'); continue; } $reserveInstance = $orderModel->getReserve(); if (!$reserveInstance->isClosed()) {