kiy0taka /
ec-cube
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /* |
||
| 3 | * This file is part of EC-CUBE |
||
| 4 | * |
||
| 5 | * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
||
| 6 | * |
||
| 7 | * http://www.lockon.co.jp/ |
||
| 8 | * |
||
| 9 | * This program is free software; you can redistribute it and/or |
||
| 10 | * modify it under the terms of the GNU General Public License |
||
| 11 | * as published by the Free Software Foundation; either version 2 |
||
| 12 | * of the License, or (at your option) any later version. |
||
| 13 | * |
||
| 14 | * This program is distributed in the hope that it will be useful, |
||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 17 | * GNU General Public License for more details. |
||
| 18 | * |
||
| 19 | * You should have received a copy of the GNU General Public License |
||
| 20 | * along with this program; if not, write to the Free Software |
||
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
||
| 22 | */ |
||
| 23 | |||
| 24 | |||
| 25 | namespace Eccube\Controller\Admin\Setting\System; |
||
| 26 | |||
| 27 | use Doctrine\Common\Persistence\Mapping\MappingException; |
||
| 28 | use Eccube\Application; |
||
| 29 | use Eccube\Controller\AbstractController; |
||
| 30 | use Eccube\Event\EccubeEvents; |
||
| 31 | use Eccube\Event\EventArgs; |
||
| 32 | use Symfony\Component\HttpFoundation\Request; |
||
| 33 | |||
| 34 | class MasterdataController extends AbstractController |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 35 | { |
||
| 36 | 2 | public function index(Application $app, Request $request, $entity = null) |
|
|
0 ignored issues
–
show
|
|||
| 37 | { |
||
| 38 | 2 | $data = array(); |
|
| 39 | |||
| 40 | 2 | $builder = $app['form.factory']->createBuilder('admin_system_masterdata'); |
|
| 41 | |||
| 42 | 2 | $event = new EventArgs( |
|
| 43 | array( |
||
| 44 | 2 | 'builder' => $builder, |
|
| 45 | ), |
||
| 46 | $request |
||
| 47 | ); |
||
| 48 | 2 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_INDEX_INITIALIZE, $event); |
|
| 49 | |||
| 50 | 2 | $form = $builder->getForm(); |
|
| 51 | |||
| 52 | 2 | if ('POST' === $request->getMethod()) { |
|
| 53 | 1 | $form->handleRequest($request); |
|
| 54 | 1 | if ($form->isValid()) { |
|
| 55 | 1 | $event = new EventArgs( |
|
| 56 | array( |
||
| 57 | 1 | 'form' => $form, |
|
| 58 | ), |
||
| 59 | $request |
||
| 60 | ); |
||
| 61 | 1 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_INDEX_COMPLETE, $event); |
|
| 62 | |||
| 63 | 1 | if ($event->hasResponse()) { |
|
| 64 | return $event->getResponse(); |
||
| 65 | } |
||
| 66 | |||
| 67 | 1 | return $app->redirect($app->url('admin_setting_system_masterdata_view', array('entity' => $form['masterdata']->getData()))); |
|
| 68 | } |
||
| 69 | 2 | } elseif (!is_null($entity)) { |
|
| 70 | 1 | $form->submit(array('masterdata' => $entity)); |
|
| 71 | 1 | if ($form['masterdata']->isValid()) { |
|
| 72 | 1 | $entityName = str_replace('-', '\\', $entity); |
|
| 73 | try { |
||
| 74 | 1 | $masterdata = $app['orm.em']->getRepository($entityName)->findBy(array(), array('rank' => 'ASC')); |
|
| 75 | 1 | $data['data'] = array(); |
|
| 76 | 1 | $data['masterdata_name'] = $entity; |
|
| 77 | 1 | foreach ($masterdata as $value) { |
|
| 78 | 1 | $data['data'][$value['id']]['id'] = $value['id']; |
|
| 79 | 1 | $data['data'][$value['id']]['name'] = $value['name']; |
|
| 80 | } |
||
| 81 | 1 | $data['data'][] = array( |
|
| 82 | 1 | 'id' => '', |
|
| 83 | 'name' => '', |
||
| 84 | ); |
||
| 85 | } catch (MappingException $e) { |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | 2 | $builder2 = $app['form.factory']->createBuilder('admin_system_masterdata_edit', $data); |
|
| 91 | |||
| 92 | 2 | $event = new EventArgs( |
|
| 93 | array( |
||
| 94 | 2 | 'builder' => $builder2, |
|
| 95 | ), |
||
| 96 | $request |
||
| 97 | ); |
||
| 98 | 2 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_INDEX_FORM2_INITIALIZE, $event); |
|
| 99 | |||
| 100 | 2 | $form2 = $builder2->getForm(); |
|
| 101 | |||
| 102 | 2 | return $app->render('Setting/System/masterdata.twig', array( |
|
| 103 | 2 | 'form' => $form->createView(), |
|
| 104 | 2 | 'form2' => $form2->createView(), |
|
| 105 | )); |
||
| 106 | } |
||
| 107 | |||
| 108 | 9 | public function edit(Application $app, Request $request) |
|
|
0 ignored issues
–
show
|
|||
| 109 | { |
||
| 110 | 9 | $builder2 = $app['form.factory']->createBuilder('admin_system_masterdata_edit'); |
|
| 111 | |||
| 112 | 9 | $event = new EventArgs( |
|
| 113 | array( |
||
| 114 | 9 | 'builder' => $builder2, |
|
| 115 | ), |
||
| 116 | $request |
||
| 117 | ); |
||
| 118 | 9 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_EDIT_INITIALIZE, $event); |
|
| 119 | |||
| 120 | 9 | $form2 = $builder2->getForm(); |
|
| 121 | |||
| 122 | 9 | if ('POST' === $request->getMethod()) { |
|
| 123 | 8 | $form2->handleRequest($request); |
|
| 124 | |||
| 125 | 8 | if ($form2->isValid()) { |
|
| 126 | 4 | $data = $form2->getData(); |
|
| 127 | |||
| 128 | 4 | $entityName = str_replace('-', '\\', $data['masterdata_name']); |
|
| 129 | 4 | $entity = new $entityName(); |
|
| 130 | 4 | $rank = 0; |
|
| 131 | $ids = array_map(function ($v) {return $v['id'];}, $data['data']); |
||
|
0 ignored issues
–
show
|
|||
| 132 | 4 | foreach ($data['data'] as $key => $value) { |
|
| 133 | 4 | if ($value['id'] !== null && $value['name'] !== null) { |
|
| 134 | 4 | $entity->setId($value['id']); |
|
| 135 | 4 | $entity->setName($value['name']); |
|
| 136 | 4 | $entity->setRank($rank++); |
|
| 137 | 4 | $app['orm.em']->merge($entity); |
|
| 138 | 1 | } elseif (!in_array($key, $ids)) { |
|
| 139 | // remove |
||
| 140 | $delKey = $app['orm.em']->getRepository($entityName)->find($key); |
||
| 141 | if ($delKey) { |
||
| 142 | 4 | $app['orm.em']->remove($delKey); |
|
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | try { |
||
| 148 | 4 | $app['orm.em']->flush(); |
|
| 149 | |||
| 150 | 4 | $event = new EventArgs( |
|
| 151 | array( |
||
| 152 | 4 | 'form' => $form2, |
|
| 153 | ), |
||
| 154 | $request |
||
| 155 | ); |
||
| 156 | 4 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_EDIT_COMPLETE, $event); |
|
| 157 | |||
| 158 | 4 | $app->addSuccess('admin.register.complete', 'admin'); |
|
| 159 | } catch (\Exception $e) { |
||
| 160 | // 外部キー制約などで削除できない場合に例外エラーになる |
||
| 161 | $app->addError('admin.register.failed', 'admin'); |
||
| 162 | } |
||
| 163 | |||
| 164 | 4 | return $app->redirect($app->url('admin_setting_system_masterdata_view', array('entity' => $data['masterdata_name']))); |
|
| 165 | } |
||
| 166 | } |
||
| 167 | |||
| 168 | 5 | $builder = $app['form.factory']->createBuilder('admin_system_masterdata'); |
|
| 169 | |||
| 170 | 5 | $event = new EventArgs( |
|
| 171 | array( |
||
| 172 | 5 | 'builder' => $builder, |
|
| 173 | ), |
||
| 174 | $request |
||
| 175 | ); |
||
| 176 | 5 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_EDIT_FORM_INITIALIZE, $event); |
|
| 177 | |||
| 178 | 5 | $form = $builder->getForm(); |
|
| 179 | 5 | $parameter = array_merge($request->request->all(), array('masterdata' => $form2['masterdata_name']->getData())); |
|
| 180 | 5 | $form->submit($parameter); |
|
| 181 | |||
| 182 | 5 | return $app->render('Setting/System/masterdata.twig', array( |
|
| 183 | 5 | 'form' => $form->createView(), |
|
| 184 | 5 | 'form2' => $form2->createView(), |
|
| 185 | )); |
||
| 186 | } |
||
| 187 | } |
||
| 188 |