1 | <?php |
||
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) { |
||
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) { |
||
110 | } |
||
111 |