/** * Index * * @param Application $app * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function index(Application $app, Request $request) { /* @var $form \Symfony\Component\Form\FormInterface */ $form = $app->form()->getForm(); if ('POST' === $request->getMethod()) { $form->handleRequest($request); if ($form->isValid()) { switch ($request->get('mode')) { case 'confirm': return $app->renderView('Mypage/withdraw_confirm.twig', array('form' => $form->createView())); case 'complete': /* @var $Customer \Eccube\Entity\Customer */ $Customer = $app->user(); // 会員削除 $email = $Customer->getEmail(); // メールアドレスにダミーをセット $Customer->setEmail(Str::random(60) . '@dummy.dummy'); $Customer->setDelFlg(Constant::ENABLED); $app['orm.em']->flush(); // メール送信 $app['eccube.service.mail']->sendCustomerWithdrawMail($Customer, $email); // ログアウト $this->getSecurity($app)->setToken(null); return $app->redirect($app->url('mypage_withdraw_complete')); } } } return $app->renderView('Mypage/withdraw.twig', array('form' => $form->createView())); }
/** * 退会画面. * * @param Application $app * @param Request $request * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function index(Application $app, Request $request) { $builder = $app->form(); $event = new EventArgs(array('builder' => $builder), $request); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_WITHDRAW_INDEX_INITIALIZE, $event); $form = $builder->getForm(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { switch ($request->get('mode')) { case 'confirm': return $app->render('Mypage/withdraw_confirm.twig', array('form' => $form->createView())); case 'complete': /* @var $Customer \Eccube\Entity\Customer */ $Customer = $app->user(); // 会員削除 $email = $Customer->getEmail(); // メールアドレスにダミーをセット $Customer->setEmail(Str::random(60) . '@dummy.dummy'); $Customer->setDelFlg(Constant::ENABLED); $app['orm.em']->flush(); $event = new EventArgs(array('form' => $form, 'Customer' => $Customer), $request); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_WITHDRAW_INDEX_COMPLETE, $event); // メール送信 $app['eccube.service.mail']->sendCustomerWithdrawMail($Customer, $email); // ログアウト $this->getSecurity($app)->setToken(null); return $app->redirect($app->url('mypage_withdraw_complete')); } } return $app->render('Mypage/withdraw.twig', array('form' => $form->createView())); }
public function createTempDir() { @mkdir($this->app['config']['plugin_temp_realdir']); $d = $this->app['config']['plugin_temp_realdir'] . '/' . sha1(Str::random(16)); if (!mkdir($d, 0777)) { throw new PluginException($php_errormsg . $d); } return $d; }
public function testRandomException() { $this->expected = 'Unable to generate random string.'; try { $result = Str::random(0); $this->fail(); } catch (\RuntimeException $e) { $this->actual = $e->getMessage(); } $this->assertEquals($this->expected, $this->actual); }
public function testCountCouponByCd() { $Coupon = $this->getCoupon(); $discount = 200; $preOrderId = sha1(Str::random(32)); $CouponOrder = $this->getCouponOrder($Coupon, $discount, $preOrderId); $CouponOrder->setOrderDate(new \DateTime()); $this->app['eccube.plugin.coupon.repository.coupon_order']->save($CouponOrder); $count = $this->app['eccube.plugin.coupon.repository.coupon_order']->countCouponByCd($Coupon->getCouponCd()); $this->actual = $count['1']; $this->expected = 1; $this->verify(); }
public function update(Application $app, $id) { $Plugin = $app['eccube.repository.plugin']->find($id); $form = $app['form.factory']->createNamedBuilder('form' . $id, 'plugin_management', null, array('plugin_id' => null, 'enable' => null))->getForm(); $form->handleRequest($app['request']); $tmpDir = $app['eccube.service.plugin']->createTempDir(); $tmpFile = sha1(Str::random(32)) . ".tar"; $form['plugin_archive']->getData()->move($tmpDir, $tmpFile); $app['eccube.service.plugin']->update($Plugin, $tmpDir . '/' . $tmpFile); $app->addSuccess('admin.plugin.update.complete', 'admin'); $fs = new Filesystem(); $fs->remove($tmpDir . '/' . $tmpFile); return $app->redirect($app->url('admin_setting_store_plugin')); }
/** * アップロードされたCSVファイルの行ごとの処理 * * @param $formFile * @return CsvImportService */ protected function getImportData($app, $formFile) { // アップロードされたCSVファイルを一時ディレクトリに保存 $this->fileName = 'upload_' . Str::random() . '.' . $formFile->getClientOriginalExtension(); $formFile->move($app['config']['csv_temp_realdir'], $this->fileName); $file = file_get_contents($app['config']['csv_temp_realdir'] . '/' . $this->fileName); // アップロードされたファイルがUTF-8以外は文字コード変換を行う $encode = Str::characterEncoding(substr($file, 0, 6)); if ($encode != 'UTF-8') { $file = mb_convert_encoding($file, 'UTF-8', $encode); } $file = Str::convertLineFeed($file); $tmp = tmpfile(); fwrite($tmp, $file); rewind($tmp); $meta = stream_get_meta_data($tmp); $file = new \SplFileObject($meta['uri']); set_time_limit(0); // アップロードされたCSVファイルを行ごとに取得 $data = new CsvImportService($file, $app['config']['csv_import_delimiter'], $app['config']['csv_import_enclosure']); $data->setHeaderRowNumber(0); return $data; }
/** * アップロードされたCSVファイルの行ごとの処理 * * @param $formFile * @return CsvImportService */ protected function getImportData($app, $formFile) { // アップロードされたCSVファイルを一時ディレクトリに保存 $this->fileName = 'upload_' . Str::random() . '.' . $formFile->getClientOriginalExtension(); $formFile->move($app['config']['csv_temp_realdir'], $this->fileName); $file = file_get_contents($app['config']['csv_temp_realdir'] . '/' . $this->fileName); if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID >= 70000) { // Windows 環境の PHP7 の場合はファイルエンコーディングを CP932 に合わせる // see https://github.com/EC-CUBE/ec-cube/issues/1780 setlocale(LC_ALL, ''); // 既定のロケールに設定 if (mb_detect_encoding($file) === 'UTF-8') { // UTF-8 を検出したら SJIS-win に変換 $file = mb_convert_encoding($file, 'SJIS-win', 'UTF-8'); } } else { // アップロードされたファイルがUTF-8以外は文字コード変換を行う $encode = Str::characterEncoding(substr($file, 0, 6)); if ($encode != 'UTF-8') { $file = mb_convert_encoding($file, 'UTF-8', $encode); } } $file = Str::convertLineFeed($file); $tmp = tmpfile(); fwrite($tmp, $file); rewind($tmp); $meta = stream_get_meta_data($tmp); $file = new \SplFileObject($meta['uri']); set_time_limit(0); // アップロードされたCSVファイルを行ごとに取得 $data = new CsvImportService($file, $app['config']['csv_import_delimiter'], $app['config']['csv_import_enclosure']); $ret = $data->setHeaderRowNumber(0); return $ret !== false ? $data : false; }
public function testSave() { $cartService = $this->app['eccube.service.cart']; $preOrderId = sha1(Str::random(32)); $cartService->setPreOrderId($preOrderId); $cartService->save(); $this->expected = $preOrderId; $this->actual = $this->app['session']->get('cart')->getPreOrderId(); $this->verify(); }
/** * オーナーズブラグインインストール、アップデート * * @param Application $app * @param Request $request * @param $action * @param $id * @param $version */ public function upgrade(Application $app, Request $request, $action, $id, $version) { $BaseInfo = $app['eccube.repository.base_info']->get(); $authKey = $BaseInfo->getAuthenticationKey(); $message = ''; if (!is_null($authKey)) { // オーナーズストア通信 $url = $app['config']['owners_store_url'] . '?method=download&product_id=' . $id; list($json, $httpHeader) = $this->getRequestApi($request, $authKey, $url); if ($json === false) { // 接続失敗時 $message = $this->getResponseErrorMessage($httpHeader); } else { // 接続成功時 $data = json_decode($json, true); if (isset($data['success'])) { $success = $data['success']; if ($success == '1') { $tmpDir = null; try { $service = $app['eccube.service.plugin']; $item = $data['item']; $file = base64_decode($item['data']); $extension = pathinfo($item['file_name'], PATHINFO_EXTENSION); $tmpDir = $service->createTempDir(); $tmpFile = sha1(Str::random(32)) . '.' . $extension; // ファイル作成 $fs = new Filesystem(); $fs->dumpFile($tmpDir . '/' . $tmpFile, $file); if ($action == 'install') { $service->install($tmpDir . '/' . $tmpFile, $id); $app->addSuccess('admin.plugin.install.complete', 'admin'); } else { if ($action == 'update') { $Plugin = $app['eccube.repository.plugin']->findOneBy(array('source' => $id)); $service->update($Plugin, $tmpDir . '/' . $tmpFile); $app->addSuccess('admin.plugin.update.complete', 'admin'); Cache::clear($app, false); } } $fs = new Filesystem(); $fs->remove($tmpDir); // ダウンロード完了通知処理(正常終了時) $url = $app['config']['owners_store_url'] . '?method=commit&product_id=' . $id . '&status=1&version=' . $version; $this->getRequestApi($request, $authKey, $url); return $app->redirect($app->url('admin_store_plugin')); } catch (PluginException $e) { if (!empty($tmpDir) && file_exists($tmpDir)) { $fs = new Filesystem(); $fs->remove($tmpDir); } $message = $e->getMessage(); } } else { $message = $data['error_code'] . ' : ' . $data['error_message']; } } else { $message = "EC-CUBEオーナーズストアにエラーが発生しています。"; } } } // ダウンロード完了通知処理(エラー発生時) $url = $app['config']['owners_store_url'] . '?method=commit&product_id=' . $id . '&status=0&version=' . $version . '&message=' . urlencode($message); $this->getRequestApi($request, $authKey, $url); $app->addError($message, 'admin'); return $app->redirect($app->url('admin_store_plugin_owners_install')); }
private function createConfigYamlFile($data) { $fs = new Filesystem(); $config_file = $this->config_path . '/config.yml'; if ($fs->exists($config_file)) { $fs->remove($config_file); } $auth_magic = Str::random(32); $allowHost = Str::convertLineFeed($data['admin_allow_hosts']); if (empty($allowHost)) { $adminAllowHosts = array(); } else { $adminAllowHosts = explode("\n", $allowHost); } $target = array('${AUTH_MAGIC}', '${SHOP_NAME}', '${ECCUBE_INSTALL}', '${FORCE_SSL}'); $replace = array($auth_magic, $data['shop_name'], '0', $data['admin_force_ssl']); $fs = new Filesystem(); $content = str_replace($target, $replace, file_get_contents($this->dist_path . '/config.yml.dist')); $fs->dumpFile($config_file, $content); $config = Yaml::Parse($config_file); $config['admin_allow_host'] = $adminAllowHosts; $yml = Yaml::dump($config); file_put_contents($config_file, $yml); return $this; }
/** * 受注情報を作成 * * @param $Customer * @return \Eccube\Entity\Order */ public function createOrder($Customer) { // ランダムなpre_order_idを作成 $preOrderId = sha1(Str::random(32)); // 受注情報、受注明細情報、お届け先情報、配送商品情報を作成 $Order = $this->registerPreOrder($Customer, $preOrderId); $this->cartService->setPreOrderId($preOrderId); $this->cartService->save(); return $Order; }
public function getResetPassword() { return Str::random(8); }
public function add(Application $app, Request $request) { /** @var $Template \Eccube\Entity\Template */ $Template = new \Eccube\Entity\Template(); $form = $app['form.factory']->createBuilder('admin_template', $Template)->getForm(); if ('POST' === $request->getMethod()) { $form->handleRequest($request); if ($form->isValid()) { /** @var $Template \Eccube\Entity\Template */ $tem = $app['eccube.repository.template']->findByCode($form['code']->getData()); // テンプレートコードの重複チェック. if ($tem) { $form['code']->addError(new FormError('すでに登録されているテンプレートコードです。')); return false; } // 該当テンプレートのディレクトリ $config = $app['config']; $templateCode = $Template->getCode(); $targetRealDir = $config['root_dir'] . '/app/template/' . $templateCode; $targetHtmlRealDir = $config['root_dir'] . '/html/template/' . $templateCode; // 一時ディレクトリ $uniqId = sha1(Str::random(32)); $tmpDir = $config['template_temp_realdir'] . '/' . $uniqId; $appDir = $tmpDir . '/app'; $htmlDir = $tmpDir . '/html'; $formFile = $form['file']->getData(); // ファイル名 $archive = $templateCode . '.' . $formFile->getClientOriginalExtension(); // ファイルを一時ディレクトリへ移動. $formFile->move($tmpDir, $archive); // 一時ディレクトリへ解凍する. try { if ($formFile->getClientOriginalExtension() == 'zip') { $zip = new \ZipArchive(); $zip->open($tmpDir . '/' . $archive); $zip->extractTo($tmpDir); $zip->close(); } else { $phar = new \PharData($tmpDir . '/' . $archive); $phar->extractTo($tmpDir, null, true); } } catch (\Exception $e) { $form['file']->addError(new FormError('アップロードに失敗しました。圧縮ファイルを確認してください。')); return $app->render('Store/template_add.twig', array('form' => $form->createView())); } // appディレクトリの存在チェック. if (!file_exists($appDir)) { $form['file']->addError(new FormError('appディレクトリが見つかりません。ファイルの形式を確認してください。')); if (file_exists($tmpDir)) { $fs = new Filesystem(); $fs->remove($tmpDir); } return $app->render('Store/template_add.twig', array('form' => $form->createView())); } // htmlディレクトリの存在チェック. if (!file_exists($htmlDir)) { $form['file']->addError(new FormError('htmlディレクトリが見つかりません。ファイルの形式を確認してください。')); if (file_exists($tmpDir)) { $fs = new Filesystem(); $fs->remove($tmpDir); } return $app->render('Store/template_add.twig', array('form' => $form->createView())); } // 一時ディレクトリから該当テンプレートのディレクトリへコピーする. $fs = new Filesystem(); $fs->mirror($appDir, $targetRealDir); $fs->mirror($htmlDir, $targetHtmlRealDir); // 一時ディレクトリを削除. $fs->remove($tmpDir); $DeviceType = $app['eccube.repository.master.device_type']->find(DeviceType::DEVICE_TYPE_PC); $Template->setDeviceType($DeviceType); $app['orm.em']->persist($Template); $app['orm.em']->flush(); $app->addSuccess('admin.content.template.add.complete', 'admin'); return $app->redirect($app->url('admin_store_template')); } } return $app->render('Store/template_add.twig', array('form' => $form->createView())); }
public function createTempDir() { $base = __DIR__ . '/../../../app/cache/plugin'; @mkdir($base); $d = $base . '/' . sha1(Str::random(16)); if (!mkdir($d, 0777)) { throw new PluginException($php_errormsg . $d); } return $d; }
function initializeDatabase(\Eccube\Application $app) { // Get an instance of your entity manager $entityManager = $app['orm.em']; $pdo = $entityManager->getConnection()->getWrappedConnection(); // Clear Doctrine to be safe $entityManager->getConnection()->getConfiguration()->setSQLLogger(null); $entityManager->clear(); gc_collect_cycles(); // Schema Tool to process our entities $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $classes = $entityManager->getMetaDataFactory()->getAllMetaData(); // Drop all classes and re-build them for each test case out('Dropping database schema...', 'info'); $tool->dropSchema($classes); out('Creating database schema...', 'info'); $tool->createSchema($classes); out('Database schema created successfully!', 'success'); $config = new \Doctrine\DBAL\Migrations\Configuration\Configuration($app['db']); $config->setMigrationsNamespace('DoctrineMigrations'); $migrationDir = __DIR__ . '/src/Eccube/Resource/doctrine/migration'; $config->setMigrationsDirectory($migrationDir); $config->registerMigrationsFromDirectory($migrationDir); $migration = new \Doctrine\DBAL\Migrations\Migration($config); $migration->migrate(); out('Database migration successfully!', 'success'); $login_id = getenv('ADMIN_USER'); $login_password = getenv('ADMIN_PASS'); $passwordEncoder = new \Eccube\Security\Core\Encoder\PasswordEncoder($app['config']); $salt = \Eccube\Util\Str::random(32); $encodedPassword = $passwordEncoder->encodePassword($login_password, $salt); out('Creating admin accounts...', 'info'); $sql = "INSERT INTO dtb_member (member_id, login_id, password, salt, work, del_flg, authority, creator_id, rank, update_date, create_date,name,department) VALUES (2, :login_id, :admin_pass , :salt , '1', '0', '0', '1', '1', current_timestamp, current_timestamp,'管理者', 'EC-CUBE SHOP');"; $stmt = $pdo->prepare($sql); $stmt->execute(array(':login_id' => $login_id, ':admin_pass' => $encodedPassword, ':salt' => $salt)); $stmt->closeCursor(); $shop_name = getenv('SHOP_NAME'); $admin_mail = getenv('ADMIN_MAIL'); $sql = "INSERT INTO dtb_base_info (id, shop_name, email01, email02, email03, email04, update_date, option_product_tax_rule) VALUES (1, :shop_name, :admin_mail1, :admin_mail2, :admin_mail3, :admin_mail4, current_timestamp, 0)"; $stmt = $pdo->prepare($sql); $stmt->execute(array(':shop_name' => $shop_name, ':admin_mail1' => $admin_mail, ':admin_mail2' => $admin_mail, ':admin_mail3' => $admin_mail, ':admin_mail4' => $admin_mail)); $stmt->closeCursor(); }
/** * 受注情報を作成 * * @param $Customer * @return \Eccube\Entity\Order */ public function createOrder($Customer) { // ランダムなpre_order_idを作成 do { $preOrderId = sha1(Str::random(32)); $Order = $this->app['eccube.repository.order']->findOneBy(array('pre_order_id' => $preOrderId, 'OrderStatus' => $this->app['config']['order_processing'])); } while ($Order); // 受注情報、受注明細情報、お届け先情報、配送商品情報を作成 $Order = $this->registerPreOrder($Customer, $preOrderId); $this->cartService->setPreOrderId($preOrderId); $this->cartService->save(); return $Order; }