mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 03:29:03 -05:00 
			
		
		
		
	Remove Unirest dependency
This commit is contained in:
		
							parent
							
								
									ebd87245af
								
							
						
					
					
						commit
						c51f27803f
					
				@ -8,8 +8,9 @@ use App\Models\Account;
 | 
				
			|||||||
use App\Models\User;
 | 
					use App\Models\User;
 | 
				
			||||||
use App\Services\Migration\CompleteService;
 | 
					use App\Services\Migration\CompleteService;
 | 
				
			||||||
use App\Traits\GenerateMigrationResources;
 | 
					use App\Traits\GenerateMigrationResources;
 | 
				
			||||||
 | 
					use GuzzleHttp\RequestOptions;
 | 
				
			||||||
use Illuminate\Support\Facades\Storage;
 | 
					use Illuminate\Support\Facades\Storage;
 | 
				
			||||||
use Unirest\Request;
 | 
					// use Unirest\Request;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class HostedMigration extends Job
 | 
					class HostedMigration extends Job
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -78,22 +79,46 @@ class HostedMigration extends Job
 | 
				
			|||||||
            'password' => '',
 | 
					            'password' => '',
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $body = \Unirest\Request\Body::json($body);
 | 
					        $client =  new \GuzzleHttp\Client([
 | 
				
			||||||
 | 
					            'headers' =>  $headers,
 | 
				
			||||||
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $response = Request::post($url, $headers, $body);
 | 
					        $response = $client->post($url,[
 | 
				
			||||||
 | 
					            RequestOptions::JSON => $body, 
 | 
				
			||||||
 | 
					            RequestOptions::ALLOW_REDIRECTS => false
 | 
				
			||||||
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (in_array($response->code, [200])) {
 | 
					        if($response->getStatusCode() == 401){
 | 
				
			||||||
 | 
					            info($response->getBody());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $data = $response->body;
 | 
					        } elseif ($response->getStatusCode() == 200) {
 | 
				
			||||||
            info(print_r($data,1));
 | 
					
 | 
				
			||||||
            $this->migration_token = $data->token; 
 | 
					            $message_body = json_decode($response->getBody(), true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $this->migration_token = $message_body['token'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            info("getting token failed");
 | 
					            info(json_decode($response->getBody()->getContents()));
 | 
				
			||||||
            info($response->raw_body);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // $body = \Unirest\Request\Body::json($body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // $response = Request::post($url, $headers, $body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // if (in_array($response->code, [200])) {
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					        //     $data = $response->body;
 | 
				
			||||||
 | 
					        //     info(print_r($data,1));
 | 
				
			||||||
 | 
					        //     $this->migration_token = $data->token; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // } else {
 | 
				
			||||||
 | 
					        //     info("getting token failed");
 | 
				
			||||||
 | 
					        //     info($response->raw_body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // }   
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -13,8 +13,9 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace App\Services\Migration;
 | 
					namespace App\Services\Migration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use Unirest\Request;
 | 
					use GuzzleHttp\RequestOptions;
 | 
				
			||||||
use Unirest\Request\Body;
 | 
					// use Unirest\Request;
 | 
				
			||||||
 | 
					// use Unirest\Request\Body;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AuthService
 | 
					class AuthService
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -51,25 +52,57 @@ class AuthService
 | 
				
			|||||||
            'password' => $this->password,
 | 
					            'password' => $this->password,
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $body = Body::json($data);
 | 
					        $client =  new \GuzzleHttp\Client([
 | 
				
			||||||
 | 
					            'headers' =>  $this->getHeaders(),
 | 
				
			||||||
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $response = Request::post($this->getUrl(), $this->getHeaders(), $body);
 | 
					        $response = $client->post($this->getUrl(),[
 | 
				
			||||||
 | 
					            RequestOptions::JSON => $data, 
 | 
				
			||||||
 | 
					            RequestOptions::ALLOW_REDIRECTS => false
 | 
				
			||||||
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (in_array($response->code, [401])) {
 | 
					 | 
				
			||||||
            info($response->raw_body);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if($response->getStatusCode() == 401){
 | 
				
			||||||
 | 
					            info($response->getBody());
 | 
				
			||||||
            $this->isSuccessful = false;
 | 
					            $this->isSuccessful = false;
 | 
				
			||||||
            $this->processErrors($response->body->message);
 | 
					            $this->processErrors($response->getBody());
 | 
				
			||||||
        } elseif (in_array($response->code, [200])) {
 | 
					        } elseif ($response->getStatusCode() == 200) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $message_body = json_decode($response->getBody(), true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            info(print_r($message_body,1));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $this->isSuccessful = true;
 | 
					            $this->isSuccessful = true;
 | 
				
			||||||
            $this->token = $response->body->data[0]->token->token;
 | 
					            $this->token = $message_body['data'][0]['token']['token'];
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            info($response->raw_body);
 | 
					            info(json_decode($response->getBody()->getContents()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $this->isSuccessful = false;
 | 
					            $this->isSuccessful = false;
 | 
				
			||||||
            $this->errors = [trans('texts.migration_went_wrong')];
 | 
					            $this->errors = [trans('texts.migration_went_wrong')];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //return $response->getBody();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // $body = Body::json($data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // $response = Request::post($this->getUrl(), $this->getHeaders(), $body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // if (in_array($response->code, [401])) {
 | 
				
			||||||
 | 
					        //     info($response->raw_body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //     $this->isSuccessful = false;
 | 
				
			||||||
 | 
					        //     $this->processErrors($response->body->message);
 | 
				
			||||||
 | 
					        // } elseif (in_array($response->code, [200])) {
 | 
				
			||||||
 | 
					        //     $this->isSuccessful = true;
 | 
				
			||||||
 | 
					        //     $this->token = $response->body->data[0]->token->token;
 | 
				
			||||||
 | 
					        // } else {
 | 
				
			||||||
 | 
					        //     info($response->raw_body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //     $this->isSuccessful = false;
 | 
				
			||||||
 | 
					        //     $this->errors = [trans('texts.migration_went_wrong')];
 | 
				
			||||||
 | 
					        // }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -3,8 +3,6 @@
 | 
				
			|||||||
namespace App\Services\Migration;
 | 
					namespace App\Services\Migration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use App\Models\Account;
 | 
					use App\Models\Account;
 | 
				
			||||||
use Unirest\Request;
 | 
					 | 
				
			||||||
use Unirest\Request\Body;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CompanyService
 | 
					class CompanyService
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
				
			|||||||
@ -2,8 +2,9 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace App\Services\Migration;
 | 
					namespace App\Services\Migration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use GuzzleHttp\RequestOptions;
 | 
				
			||||||
use Illuminate\Support\Facades\Storage;
 | 
					use Illuminate\Support\Facades\Storage;
 | 
				
			||||||
use Unirest\Request;
 | 
					// use Unirest\Request;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CompleteService
 | 
					class CompleteService
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -45,22 +46,48 @@ class CompleteService
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        foreach ($this->data as $companyKey => $companyData) {
 | 
					        foreach ($this->data as $companyKey => $companyData) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $data[] = [
 | 
					            $data = [
 | 
				
			||||||
                'company_index' => $companyKey,
 | 
					                'company_index' => $companyKey,
 | 
				
			||||||
                'company_key' => $companyData['data']['company']['company_key'],
 | 
					                'company_key' => $companyData['data']['company']['company_key'],
 | 
				
			||||||
                'force' => $companyData['force'],
 | 
					                'force' => $companyData['force'],
 | 
				
			||||||
 | 
					                'contents' => 'name',
 | 
				
			||||||
 | 
					                'name' => $companyKey, 
 | 
				
			||||||
            ];
 | 
					            ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $files[$companyKey] = $companyData['file'];
 | 
					            $payload[$companyKey] = [
 | 
				
			||||||
 | 
					                'contents' => json_encode($data),
 | 
				
			||||||
 | 
					                'name' => $companyData['data']['company']['company_key'],
 | 
				
			||||||
 | 
					            ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $files[] = [
 | 
				
			||||||
 | 
					                'name' => $companyKey, 
 | 
				
			||||||
 | 
					                'company_index' => $companyKey,
 | 
				
			||||||
 | 
					                'company_key' => $companyData['data']['company']['company_key'],
 | 
				
			||||||
 | 
					                'force' => $companyData['force'],
 | 
				
			||||||
 | 
					                'contents' => file_get_contents($companyData['file']),
 | 
				
			||||||
 | 
					                'filename' => basename($companyData['file']),
 | 
				
			||||||
 | 
					                'Content-Type' => 'application/zip'
 | 
				
			||||||
 | 
					            ];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $body = \Unirest\Request\Body::multipart(['companies' => json_encode($data)], $files);
 | 
					        $client =  new \GuzzleHttp\Client(
 | 
				
			||||||
 | 
					        [
 | 
				
			||||||
 | 
					            'headers' => $this->getHeaders(),
 | 
				
			||||||
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $response = Request::post($this->getUrl(), $this->getHeaders(), $body);
 | 
					 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        if (in_array($response->code, [200])) {
 | 
					        $payload_data = [
 | 
				
			||||||
 | 
					                'multipart'=> array_merge($files, $payload),
 | 
				
			||||||
 | 
					             ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        info(print_r($payload_data,1));
 | 
				
			||||||
 | 
					        $response = $client->request("POST", $this->getUrl(),$payload_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if($response->getStatusCode() == 200){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $this->isSuccessful = true;
 | 
					            $this->isSuccessful = true;
 | 
				
			||||||
        } else {
 | 
					            return json_decode($response->getBody(),true);
 | 
				
			||||||
 | 
					        }else {
 | 
				
			||||||
            info($response->raw_body);
 | 
					            info($response->raw_body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $this->isSuccessful = false;
 | 
					            $this->isSuccessful = false;
 | 
				
			||||||
@ -70,6 +97,26 @@ class CompleteService
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // $body = \Unirest\Request\Body::multipart(['companies' => json_encode($data)], $files);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // $response = Request::post($this->getUrl(), $this->getHeaders(), $body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // if (in_array($response->code, [200])) {
 | 
				
			||||||
 | 
					        //     $this->isSuccessful = true;
 | 
				
			||||||
 | 
					        // } else {
 | 
				
			||||||
 | 
					        //     info($response->raw_body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //     $this->isSuccessful = false;
 | 
				
			||||||
 | 
					        //     $this->errors = [
 | 
				
			||||||
 | 
					        //         'Oops, something went wrong. Migration can\'t be processed at the moment. Please checks the logs.',
 | 
				
			||||||
 | 
					        //     ];
 | 
				
			||||||
 | 
					        // }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function isSuccessful()
 | 
					    public function isSuccessful()
 | 
				
			||||||
 | 
				
			|||||||
@ -68,7 +68,6 @@
 | 
				
			|||||||
        "league/fractal": "0.13.*",
 | 
					        "league/fractal": "0.13.*",
 | 
				
			||||||
        "lokielse/omnipay-alipay": "~1.4",
 | 
					        "lokielse/omnipay-alipay": "~1.4",
 | 
				
			||||||
        "maatwebsite/excel": "dev-carbon#8b17952",
 | 
					        "maatwebsite/excel": "dev-carbon#8b17952",
 | 
				
			||||||
        "mashape/unirest-php": "^3.0.4",
 | 
					 | 
				
			||||||
        "meebio/omnipay-creditcall": "dev-master",
 | 
					        "meebio/omnipay-creditcall": "dev-master",
 | 
				
			||||||
        "meebio/omnipay-secure-trading": "dev-master",
 | 
					        "meebio/omnipay-secure-trading": "dev-master",
 | 
				
			||||||
        "mfauveau/omnipay-pacnet": "~2.0",
 | 
					        "mfauveau/omnipay-pacnet": "~2.0",
 | 
				
			||||||
 | 
				
			|||||||
@ -2,7 +2,7 @@
 | 
				
			|||||||
// This is global bootstrap for autoloading
 | 
					// This is global bootstrap for autoloading
 | 
				
			||||||
use Codeception\Util\Fixtures;
 | 
					use Codeception\Util\Fixtures;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Fixtures::add('url', 'http://www.ninja.test:8000');
 | 
					Fixtures::add('url', 'http://ninja-master.test:8000');
 | 
				
			||||||
Fixtures::add('username', 'user@example.com');
 | 
					Fixtures::add('username', 'user@example.com');
 | 
				
			||||||
Fixtures::add('permissions_username', 'permissions@example.com');
 | 
					Fixtures::add('permissions_username', 'permissions@example.com');
 | 
				
			||||||
Fixtures::add('password', 'password');
 | 
					Fixtures::add('password', 'password');
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user