1
|
|
|
<?php |
2
|
|
|
namespace Etobi\CoreAPI\Service; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2012 Georg Ringer <[email protected]> |
8
|
|
|
* (c) 2014 Stefano Kowalke <[email protected]> |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
use InvalidArgumentException; |
28
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* DB API service |
32
|
|
|
* |
33
|
|
|
* @author Georg Ringer <[email protected]> |
34
|
|
|
* @author Stefano Kowalke <[email protected]> |
35
|
|
|
* @package Etobi\CoreAPI\Service\SiteApiService |
36
|
|
|
*/ |
37
|
|
|
class DatabaseApiService { |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager |
41
|
|
|
*/ |
42
|
|
|
protected $objectManager; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var \Etobi\CoreAPI\Service\DatabaseComparator $comparator |
46
|
|
|
*/ |
47
|
|
|
protected $comparator = NULL; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Inject the ObjectManager |
51
|
|
|
* |
52
|
|
|
* @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager |
53
|
|
|
*/ |
54
|
|
|
public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager) { |
55
|
|
|
$this->objectManager = $objectManager; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Database compare. |
60
|
|
|
* |
61
|
|
|
* @param string $actions comma separated list of IDs |
62
|
|
|
* @param boolean $dry |
63
|
|
|
* |
64
|
|
|
* @throws \InvalidArgumentException |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
3 |
|
public function databaseCompare($actions, $dry) { |
68
|
3 |
|
if ($dry) { |
69
|
1 |
|
$this->comparator = $this->objectManager->get('Etobi\\CoreAPI\\Service\\DatabaseCompareDry'); |
70
|
1 |
|
} else { |
71
|
2 |
|
$this->comparator = $this->objectManager->get('Etobi\\CoreAPI\\Service\\DatabaseCompareReal'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
try { |
75
|
3 |
|
$result = $this->comparator->databaseCompare($actions); |
76
|
3 |
|
} catch (\Exception $e) { |
77
|
|
|
throw new \InvalidArgumentException($e->getMessage()); |
78
|
|
|
} |
79
|
|
|
|
80
|
3 |
|
return $result; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get all available actions. |
85
|
|
|
* |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
public function databaseCompareAvailableActions() { |
89
|
|
|
$availableActions = array_flip($this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ClassReflection', 'Etobi\\CoreAPI\\Service\\DatabaseComparator')->getConstants()); |
90
|
|
|
|
91
|
|
|
foreach ($availableActions as $number => $action) { |
92
|
|
|
if (!$this->isFirstPartOfString($action, 'ACTION_')) { |
93
|
|
|
unset($availableActions[$number]); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
return $availableActions; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Wrapper around GeneralUtility::isFirstPartOfStr() |
101
|
|
|
* |
102
|
|
|
* @param string $str |
103
|
|
|
* @param string $partStr |
104
|
|
|
* |
105
|
|
|
* @return bool |
106
|
|
|
*/ |
107
|
|
|
protected function isFirstPartOfString($str, $partStr) { |
108
|
|
|
return GeneralUtility::isFirstPartOfStr($str, $partStr); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|