function afterDestroy($oldMe)
 {
     $this->parentAfterDestroy($oldMe);
     $oldId = $this->bean->old("id");
     $classname = $this->classname();
     $imagePath = S3Helpers::key($this->app->config('publicDir'), 'images/' . $classname . '/' . $oldId . '/');
     $this->S3DeleteDir($imagePath);
 }
 public function S3ProcessDestroyImage($instance, $imageSetting, $imageField, $position)
 {
     if (!$instance->hasError()) {
         try {
             $amazonS3Config = $this->app->config('amazonS3');
             $client = S3Client::factory($amazonS3Config['settings']);
             $imageSettings = $this->getImageSettings();
             if ($imageSettings[$imageSetting]["_config"]["multiple"]) {
                 $imageValue = $instance->get($imageField);
                 if (!is_array($imageValue)) {
                     $imageValue = UtilitiesHelper::decodeJson($imageValue, true);
                 }
                 $imagesAtPosition = $imageValue[$position];
                 if (!empty($imagesAtPosition)) {
                     if (!empty($imageSettings[$imageSetting]["types"])) {
                         //multiple many types
                         foreach ($imagesAtPosition as $key => $image) {
                             $client->deleteObject(array('Bucket' => $amazonS3Config['bucket'], 'Key' => S3Helpers::key($this->app->config('publicDir'), $image)));
                         }
                     } else {
                         //multiple single types
                         $client->deleteObject(array('Bucket' => $amazonS3Config['bucket'], 'Key' => S3Helpers::key($this->app->config('publicDir'), $imagesAtPosition)));
                     }
                 }
                 unset($imageValue[$position]);
                 $imageValue = array_values($imageValue);
                 $instance->set($imageField, json_encode($imageValue));
             } else {
                 if (!$imageSettings[$imageSetting]["_config"]["multiple"] && !empty($imageSettings[$imageSetting]["types"])) {
                     $imageValue = $instance->get($imageField);
                     if (!is_array($imageValue)) {
                         $imageValue = UtilitiesHelper::decodeJson($imageValue, true);
                     }
                     if (!empty($imageValue) && is_array($imageValue)) {
                         foreach ($imageValue as $key => $image) {
                             $client->deleteObject(array('Bucket' => $amazonS3Config['bucket'], 'Key' => S3Helpers::key($this->app->config('publicDir'), $image)));
                         }
                     }
                     $instance->set($imageField, "");
                 }
             }
             R::store($instance);
             echo json_encode(array('message' => $this->app->getTranslator()->translate('deleted'), 'setting' => $imageSetting, 'field' => $imageField, 'position' => $position));
         } catch (\Exception $e) {
             $this->app->getLogger()->log("Cannot delete data : " . $e->getMessage());
         }
     }
 }
 public function getObject($path)
 {
     $s3config = $this->app->config('amazonS3');
     $result = $this->client->getObject(array('Bucket' => $s3config['bucket'], 'Key' => S3Helpers::key($this->app->config('publicDir'), $path)));
     return $result;
 }