|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Uccello\Core\Http\Controllers\Domain; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Uccello\Core\Http\Controllers\Core\EditController as CoreEditController; |
|
7
|
|
|
use Uccello\Core\Models\Domain; |
|
8
|
|
|
use Uccello\Core\Models\Module; |
|
9
|
|
|
|
|
10
|
|
|
class EditController extends CoreEditController |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* {@inheritdoc} |
|
14
|
|
|
*/ |
|
15
|
|
|
public function save(?Domain $domain, Module $module, Request $request, bool $redirect = true) |
|
16
|
|
|
{ |
|
17
|
|
|
// To use $record->setAsRoot(), we have to get the current version of the domain, |
|
18
|
|
|
// before to set parent_id = null. Because $record->setAsRoot() works only on a |
|
19
|
|
|
// domain where parent_id != null |
|
20
|
|
|
$record = Domain::find($request->get('id')); |
|
21
|
|
|
|
|
22
|
|
|
// Get mode |
|
23
|
|
|
$mode = $record->getKey() ? 'edit' : 'create'; |
|
24
|
|
|
|
|
25
|
|
|
if ($mode == 'edit') { // Config before update |
|
26
|
|
|
$this->configTree($record); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
// Default behaviour without redirection |
|
30
|
|
|
$record = parent::save($domain, $module, $request, false); // Get a fresh version of $record, after saving |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
if ($mode == 'create') { // Config after create |
|
33
|
|
|
$this->configTree($record); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
// Update current domain if we are editing it (data could have been changed) |
|
37
|
|
|
if ($this->domain->getKey() === $record->getKey()) { |
|
38
|
|
|
$this->domain = $record; |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// Redirect to detail view (we use $this->domain instead of $domain because slug could have been changed) |
|
42
|
|
|
if ($redirect === true) { |
|
43
|
|
|
$route = ucroute('uccello.detail', $this->domain, $module, [ 'id' => $record->getKey() ]); |
|
44
|
|
|
|
|
45
|
|
|
return redirect($route); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Config tree path |
|
51
|
|
|
* |
|
52
|
|
|
* @param \Uccello\Core\Models\Domain $record |
|
53
|
|
|
* @return void |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function configTree($record) |
|
56
|
|
|
{ |
|
57
|
|
|
// Set parent domain |
|
58
|
|
|
$parentDomain = Domain::find(request('parent')); |
|
59
|
|
|
if (!is_null($parentDomain)) { |
|
60
|
|
|
with($record)->setChildOf($parentDomain); |
|
61
|
|
|
} |
|
62
|
|
|
// Remove parent domain |
|
63
|
|
|
else { |
|
64
|
|
|
$record->setAsRoot(); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.