Plugin Directory

Changeset 2439247


Ignore:
Timestamp:
12/14/2020 05:39:29 PM (5 years ago)
Author:
unsproject
Message:

[1.1.0] On plugin cleanup delete data from UNS servers

  • Remove prefix from uniqueID
Location:
unsproject/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • unsproject/trunk/readme.md

    r2412807 r2439247  
    5555
    5656== Changelog ==
     57= 1.1.0 (14 Dec 2020)
     58* On plugin cleanup delete data from UNS servers
     59* Remove prefix from uniqueID
     60
    5761= 1.0.0 (04 Nov 2020) =
    5862* Initial release
  • unsproject/trunk/src/ServerCall.php

    r2412699 r2439247  
    2222        $args     = array(
    2323            'method' => strtoupper($method),
    24             'body'        => $parameters,
    25             'timeout'     => '5',
    26             'redirection' => '5',
     24            'timeout'     => isset($parameters['timeout'])
     25                ? $parameters['timeout']
     26                : 5,
     27            'redirection' => isset($parameters['redirection'])
     28                ? $parameters['redirection']
     29                : 5,
    2730        );
     31
     32        if(isset($parameters['body'])){
     33            $args['body'] = $parameters['body'];
     34        }
     35        if(isset($parameters['headers'])){
     36            $args['headers'] = $parameters['headers'];
     37        }
     38
    2839        $response = wp_remote_request( $url, $args );
    2940        $statusCode = wp_remote_retrieve_response_code( $response );
     
    5970     * @param array $parameters
    6071     * @param int $statusCode
     72     * @param null|string $callResult
    6173     * @return array
    6274     */
    63     public static function put($url, $parameters, &$statusCode){
    64         return self::call(self::REQUEST_METHOD_PUT, $url, $parameters, $statusCode);
     75    public static function put($url, $parameters, &$statusCode, &$callResult){
     76        return self::call(self::REQUEST_METHOD_PUT, $url, $parameters, $statusCode, $callResult);
    6577    }
    6678
     
    6981     * @param array $parameters
    7082     * @param int $statusCode
     83     * @param null|string $callResult
    7184     * @return array
    7285     */
    73     public static function delete($url, $parameters,&$statusCode){
    74         return self::call(self::REQUEST_METHOD_DELETE, $url, $parameters, $statusCode);
     86    public static function delete($url, $parameters,&$statusCode, &$callResult){
     87        return self::call(self::REQUEST_METHOD_DELETE, $url, $parameters, $statusCode, $callResult);
    7588    }
    7689
  • unsproject/trunk/src/UnsApp.php

    r2412699 r2439247  
    4040    /**
    4141     * @param SiteOptions $siteOption
     42     *
     43     * @return boolean
     44     * @throws Libraries\JWTException|UnsAppException
     45     */
     46    public static function deleteService($siteOption)
     47    {
     48        if(empty($siteOption->getValue('private_key'))){
     49            throw new UnsAppException('Missing plugin config. Please contact UNSproject support team to help you.');
     50        }
     51
     52        $parameters = [
     53            'body'  => [
     54                    'serviceNamespace' => $siteOption->getValue('uniqueId')
     55            ],
     56            'headers' => [
     57                'authorization' =>'Basic' . ' ' . JWT::encode(
     58                    [
     59                        'delete' => $siteOption->getValue('uniqueId')
     60                    ],
     61                    base64_decode($siteOption->getValue('private_key')),
     62                    'RS256'
     63                )
     64            ]
     65        ];
     66
     67        $url = self::API_URL. '/services';
     68        ServerCall::delete($url, $parameters, $statusCode, $result);
     69
     70         if(!in_array($statusCode, [200, 201])){
     71             throw new UnsAppException(
     72                 sprintf(
     73                     'Unable to delete the service. Status code: %s. Message: %s',
     74                     $statusCode,
     75                     strip_tags($result)
     76                 )
     77             );
     78         }
     79    }
     80   
     81    /**
     82     * @param SiteOptions $siteOption
    4283     * @return SiteOptions
    4384     * @throws \Exception
     
    4788        list($privateKey, $publicKey) = self::generateNewPrivatePublicKeys();
    4889
    49         $siteOption->setValue('public_key',base64_encode($publicKey));
    50         $siteOption->setValue('private_key',base64_encode($privateKey));
    51         $siteOption->setValue('site_url',site_url());
    52         $siteOption->setValue('uniqueId', time() . "." . str_replace(['https://','http://','/'],'', site_url()));
     90        $siteOption->setValue('public_key', base64_encode($publicKey));
     91        $siteOption->setValue('private_key', base64_encode($privateKey));
     92        $siteOption->setValue('site_url', site_url());
     93        $siteOption->setValue('uniqueId', str_replace(['https://','http://','/'],'', site_url()));
    5394
    5495        //Register website
     
    65106
    66107        $url = self::API_URL . '/services/register';
    67         $response = ServerCall::post($url, $params, $statusCode, $plainResult);
     108        $response = ServerCall::post($url, ['body' => $params] , $statusCode, $plainResult);
    68109
    69110        if (!isset($response['validationCode'])) {
     
    92133        ];
    93134
    94         $result  = ServerCall::post(self::API_URL . '/services/validate', $params, $statusCode, $plainResult);
     135        $result  = ServerCall::post(self::API_URL . '/services/validate', ['body' => $params] , $statusCode, $plainResult);
    95136        if(empty($result) && !empty($plainResult) && $plainResult !== $expectedResult){
    96137            throw  new UnsAppException('Error while validating the website. '.ucfirst(strip_tags($plainResult)), UnsAppException::VALIDATION_ERROR);
     
    132173
    133174        $url = self::API_URL . '/tickets/request';
    134         $response = ServerCall::post($url, $params, $statusCode, $plainTextResult);
     175        $response = ServerCall::post($url, ['body' => $params], $statusCode, $plainTextResult);
    135176
    136177        if (!isset($response['authenticationTicket'])) {
  • unsproject/trunk/unsproject.php

    r2412699 r2439247  
    88    Text Domain: uns-project
    99    Domain Path: /i18n
    10     Version: 1.0
     10    Version: 1.1.0
    1111*/
    1212
     
    4949
    5050    if (isset($_REQUEST['clear'])) {
    51         delete_site_option(SiteOptions::OPTION_NAME_CREDENTIALS);
    52         $databaseService = new DatabaseService();
    53         $databaseService->truncateTable(DatabaseService::TABLE_USERS);
    54         $databaseService->truncateTable(DatabaseService::TABLE_URLS);
    55         $databaseService->truncateTable(DatabaseService::TABLE_TICKETS);
    56         $siteOptions->resetAll();
     51        try {
     52            UnsApp::deleteService($siteOptions);
     53            delete_site_option(SiteOptions::OPTION_NAME_CREDENTIALS);
     54            $databaseService = new DatabaseService();
     55            $databaseService->truncateTable(DatabaseService::TABLE_USERS);
     56            $databaseService->truncateTable(DatabaseService::TABLE_URLS);
     57            $databaseService->truncateTable(DatabaseService::TABLE_TICKETS);
     58            $siteOptions->resetAll();
     59        }catch (\Exception $e){
     60            View::load('error.php', [
     61                'message' => $e->getMessage(). $e->getFile(). ':'. $e->getLine()
     62            ]);
     63        }
    5764    }
    5865
Note: See TracChangeset for help on using the changeset viewer.