Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BulkDelete() undefined method #303

Open
bootexe opened this issue May 20, 2020 · 1 comment
Open

BulkDelete() undefined method #303

bootexe opened this issue May 20, 2020 · 1 comment

Comments

@bootexe
Copy link

bootexe commented May 20, 2020

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()

@asterissco
Copy link

asterissco commented Apr 25, 2022

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants