1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) Sogilis, 2015. All Rights Reserved. |
4
|
|
|
* |
5
|
|
|
* This file is a part of Tuleap. |
6
|
|
|
* |
7
|
|
|
* Tuleap is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* Tuleap is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with Tuleap. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Tuleap\Project; |
22
|
|
|
|
23
|
|
|
use Project_Creation_Exception; |
24
|
|
|
use SystemEventProcessor_Factory; |
25
|
|
|
use SystemEvent; |
26
|
|
|
use SystemEventProcessorMutex; |
27
|
|
|
use SystemEventProcessManager; |
28
|
|
|
|
29
|
|
|
class SystemEventRunner { |
30
|
|
|
|
31
|
|
|
/** @var SystemEventProcessor_Factory */ |
32
|
|
|
private $system_event_processor_factory; |
33
|
|
|
|
34
|
|
|
public function __construct(SystemEventProcessor_Factory $system_event_processor_factory) { |
35
|
|
|
$this->system_event_processor_factory = $system_event_processor_factory; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function checkPermissions() { |
39
|
|
|
// Check we have permissions to create project and run system events |
40
|
|
|
if(posix_geteuid() != 0) { |
41
|
|
|
throw new Project_Creation_Exception("You need to be root to create a project for import"); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function runSystemEvents() { |
46
|
|
|
$processor = $this->system_event_processor_factory->getProcessForQueue(SystemEvent::DEFAULT_QUEUE); |
47
|
|
|
|
48
|
|
|
$mutex = new SystemEventProcessorMutex(new SystemEventProcessManager(), $processor); |
|
|
|
|
49
|
|
|
$mutex->waitAndExecute(); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.