Skip to content

BulkDelete() undefined method #303

Description

@bootexe

Hello
I've got a problem with Opencloud\OpenStack and I couldn't find a fix
iam trying to implement bulkDelete() but when i call the function
php throw an error saying

Fatal error: Uncaught RuntimeException: OpenStack\ObjectStore\v1\Service::bulkDelete is not defined in /Users/raphael/Dev Center/WebSite/www.photocloud.fr/vendor/php-opencloud/openstack/src/Common/Api/OperatorTrait.php:71

from this code

$openstack ->objectStoreV1() ->bulkDelete($list);

$openstack is an instance made by new OpenStack\OpenStack()

and according to the documentation there should be a bulkDelete (batchDelete at least) in the container class

I've got the same error for batchDelete()

Activity

  1. asterissco commented on Apr 25, 2022

    @asterissco

    This version no support BULK-DELETE, but you can use this to do that

    When i have time i will try to add this code to project

        public function bulkDelete($config,$arrFiles){
    
            # generate token
            $this->cnx      = new \OpenStack\OpenStack([
                'authUrl' => $config->authUrl,
                'region'  => $config->region,
                'user'    => [
                    'id'       => $config->id,
                    'password' => $config->password
                ]
            ]);
    
    
            $identity       = $this->cnx->identityV3();
            $token    = $identity->generateToken([
                'user' => [
                    'id'       => $config->id,
                    'password' => $config->password
                ]
            ]);        
    
            
            # create list of container/files to delete
            $requestBody = "";
            foreach($arrFiles as $file){
                $requestBody.=$file['container']."/".$file['name'].PHP_EOL;
            }
    
            # create request with the token to bulk-delete
            $client = new \GuzzleHttp\Client();
            $res = $client->request('DELETE', $config->uri."/?bulk-delete", [
                'headers' => 
                    [
                        'X-Auth-Token' => $token->id,
                        'Content-Type' => 'text/plain',
                        'Accept' => 'application/json'
                    ],
                'body' => $requestBody
            ]);
    
            if($res->getStatusCode()!==200){
                // return or rise exception
                return false;
            }
            if($res->getHeader('content-type')[0]=='application/json'){
                print_r(json_decode($res->getBody(),true));
                return json_decode($res->getBody(),true);
            }else{
                return $res->getBody();
            }
    
            return true;
    
        }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions