forked from VonRosenchild/ubirimi
/
CopyController.php
76 lines (60 loc) · 2.96 KB
/
CopyController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/*
* Copyright (C) 2012-2014 SC Ubirimi SRL <info-copyright@ubirimi.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
namespace Ubirimi\Yongo\Controller\Administration\Workflow;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Ubirimi\Repository\General\UbirimiLog;
use Ubirimi\SystemProduct;
use Ubirimi\UbirimiController;
use Ubirimi\Util;
use Ubirimi\Yongo\Repository\Workflow\Workflow;
class CopyController extends UbirimiController
{
public function indexAction(Request $request, SessionInterface $session)
{
Util::checkUserIsLoggedInAndRedirect();
$workflowId = $request->get('id');
$workflow = $this->getRepository(Workflow::class)->getMetaDataById($workflowId);
if ($workflow['client_id'] != $session->get('client/id')) {
return new RedirectResponse('/general-settings/bad-link-access-denied');
}
$emptyName = false;
$duplicateName = false;
if ($request->request->has('copy_workflow')) {
$name = Util::cleanRegularInputField($request->request->get('name'));
$description = Util::cleanRegularInputField($request->request->get('description'));
if (empty($name)) {
$emptyName = true;
}
$workflowAlreadyExisting = $this->getRepository(Workflow::class)->getByClientIdAndName($session->get('client/id'), $name);
if ($workflowAlreadyExisting) {
$duplicateName = true;
}
if (!$emptyName && !$workflowAlreadyExisting) {
$currentDate = Util::getServerCurrentDateTime();
$this->getRepository(Workflow::class)->copy($session->get('client/id'), $workflowId, $name, $description, $currentDate);
$this->getLogger()->addInfo('Copy Yongo Workflow ' . $workflow['name'], $this->getLoggerContext());
return new RedirectResponse('/yongo/administration/workflows');
}
}
$menuSelectedCategory = 'issue';
$sectionPageTitle = $session->get('client/settings/title_name') . ' / ' . SystemProduct::SYS_PRODUCT_YONGO_NAME . ' / Copy Workflow';
return $this->render(__DIR__ . '/../../../Resources/views/administration/workflow/Copy.php', get_defined_vars());
}
}