| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | class UpdateSecondHandProduct extends Controller | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |     private static $allowed_actions = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |         'unpublish' => '->MyPermissionCheck', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |         'archive' => '->MyPermissionCheck' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * make the page less easy to access | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * (but still accessible) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * - code => ip address | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     private static $secret_codes = array(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     public function init() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         parent::init(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         if (! $this->MyPermissionCheck()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             die('you do not have access'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     public function unpublish($request) | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $unpublished = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |         $otherID = $request->param("OtherID"); | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         if (isset($otherID)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |             $internalItemID = Convert::raw2sql($otherID); | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |             $secondHandProduct = DataObject::get_one('SecondHandProduct', ['InternalItemID' => $internalItemID]); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |             if ($secondHandProduct) { | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |                 $unpublished = $secondHandProduct->deleteFromStage('Live'); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         return json_encode($unpublished); | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     public function archive($request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $archived = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $otherID = $request->param("OtherID"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         if (isset($otherID)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             $archived = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |             } elseif (! is_null($secondHandProduct)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 $archived = $secondHandProduct->delete(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         return json_encode($archived); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @return Boolean | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     public 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.