1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
class UpdateSecondHandProduct extends Controller |
|
|
|
|
5
|
|
|
{ |
6
|
|
|
|
7
|
|
|
private static $allowed_actions = array( |
|
|
|
|
8
|
|
|
'unpublish' => '->MyPermissionCheck', |
9
|
|
|
'archive' => '->MyPermissionCheck' |
10
|
|
|
); |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* make the page less easy to access |
15
|
|
|
* (but still accessible) |
16
|
|
|
* - code => ip address |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private static $secret_codes = array(); |
|
|
|
|
20
|
|
|
|
21
|
|
|
function init() |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
parent::init(); |
24
|
|
|
if(! $this->MyPermissionCheck()) { |
25
|
|
|
die('you do not have access'); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
function unpublish($request) |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$unpublished = false; |
32
|
|
|
$otherID = $request->param("OtherID"); |
33
|
|
|
if(isset($otherID)) { |
34
|
|
|
$internalItemID = Convert::raw2sql($otherID); |
35
|
|
|
$secondHandProduct = DataObject::get_one('SecondHandProduct', ['InternalItemID' => $internalItemID]); |
36
|
|
|
if($secondHandProduct){ |
37
|
|
|
$unpublished = $secondHandProduct->deleteFromStage('Live'); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
return json_encode($unpublished); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function archive($request) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$archived = false; |
46
|
|
|
$otherID = $request->param("OtherID"); |
47
|
|
|
if(isset($otherID)) { |
48
|
|
|
$internalItemID = Convert::raw2sql($otherID); |
49
|
|
|
$secondHandProduct = DataObject::get_one('SecondHandProduct', ['InternalItemID' => $internalItemID]); |
50
|
|
|
if(!$secondHandProduct){ |
51
|
|
|
$secondHandProduct = Versioned::get_one_by_stage('SecondHandProduct', 'Stage', ['InternalItemID' => $internalItemID]); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
if (is_a($secondHandProduct, Object::getCustomClass('SiteTree'))) { |
54
|
|
|
$archived = $secondHandProduct->deleteFromStage('Live'); |
|
|
|
|
55
|
|
|
$archived = $secondHandProduct->deleteFromStage('Stage'); |
56
|
|
|
} else { |
57
|
|
|
$archived = $secondHandProduct->delete(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
return json_encode($archived); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return Boolean |
|
|
|
|
65
|
|
|
*/ |
66
|
|
|
function MyPermissionCheck() |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
$codesWithIPs = $this->Config()->get('secret_codes'); |
69
|
|
|
$code = $this->request->param('ID'); |
70
|
|
|
return ControllerPermissionChecker::permissionCheck($codesWithIPs, $code); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.