mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 11:17:34 -04: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\Services\Migration\CompleteService; | ||||
| use App\Traits\GenerateMigrationResources; | ||||
| use GuzzleHttp\RequestOptions; | ||||
| use Illuminate\Support\Facades\Storage; | ||||
| use Unirest\Request; | ||||
| // use Unirest\Request;
 | ||||
| 
 | ||||
| class HostedMigration extends Job | ||||
| { | ||||
| @ -78,21 +79,45 @@ class HostedMigration extends Job | ||||
|             '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])) { | ||||
|              | ||||
|             $data = $response->body; | ||||
|             info(print_r($data,1)); | ||||
|             $this->migration_token = $data->token;  | ||||
|         if($response->getStatusCode() == 401){ | ||||
|             info($response->getBody()); | ||||
| 
 | ||||
|         } elseif ($response->getStatusCode() == 200) { | ||||
| 
 | ||||
|             $message_body = json_decode($response->getBody(), true); | ||||
| 
 | ||||
|             $this->migration_token = $message_body['token']; | ||||
| 
 | ||||
|         } else { | ||||
|             info("getting token failed"); | ||||
|             info($response->raw_body); | ||||
|             info(json_decode($response->getBody()->getContents())); | ||||
| 
 | ||||
|         }    | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         // $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; | ||||
|     } | ||||
|  | ||||
| @ -13,8 +13,9 @@ | ||||
| 
 | ||||
| namespace App\Services\Migration; | ||||
| 
 | ||||
| use Unirest\Request; | ||||
| use Unirest\Request\Body; | ||||
| use GuzzleHttp\RequestOptions; | ||||
| // use Unirest\Request;
 | ||||
| // use Unirest\Request\Body;
 | ||||
| 
 | ||||
| class AuthService | ||||
| { | ||||
| @ -51,25 +52,57 @@ class AuthService | ||||
|             '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->processErrors($response->body->message); | ||||
|         } elseif (in_array($response->code, [200])) { | ||||
|             $this->processErrors($response->getBody()); | ||||
|         } elseif ($response->getStatusCode() == 200) { | ||||
| 
 | ||||
|             $message_body = json_decode($response->getBody(), true); | ||||
| 
 | ||||
|             info(print_r($message_body,1)); | ||||
| 
 | ||||
|             $this->isSuccessful = true; | ||||
|             $this->token = $response->body->data[0]->token->token; | ||||
|             $this->token = $message_body['data'][0]['token']['token']; | ||||
|         } else { | ||||
|             info($response->raw_body); | ||||
|             info(json_decode($response->getBody()->getContents())); | ||||
| 
 | ||||
|             $this->isSuccessful = false; | ||||
|             $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; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -3,8 +3,6 @@ | ||||
| namespace App\Services\Migration; | ||||
| 
 | ||||
| use App\Models\Account; | ||||
| use Unirest\Request; | ||||
| use Unirest\Request\Body; | ||||
| 
 | ||||
| class CompanyService | ||||
| { | ||||
|  | ||||
| @ -2,8 +2,9 @@ | ||||
| 
 | ||||
| namespace App\Services\Migration; | ||||
| 
 | ||||
| use GuzzleHttp\RequestOptions; | ||||
| use Illuminate\Support\Facades\Storage; | ||||
| use Unirest\Request; | ||||
| // use Unirest\Request;
 | ||||
| 
 | ||||
| class CompleteService | ||||
| { | ||||
| @ -45,22 +46,48 @@ class CompleteService | ||||
| 
 | ||||
|         foreach ($this->data as $companyKey => $companyData) { | ||||
| 
 | ||||
|             $data[] = [ | ||||
|             $data = [ | ||||
|                 'company_index' => $companyKey, | ||||
|                 'company_key' => $companyData['data']['company']['company_key'], | ||||
|                 '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); | ||||
|          | ||||
|         $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){ | ||||
| 
 | ||||
|         if (in_array($response->code, [200])) { | ||||
|             $this->isSuccessful = true; | ||||
|         } else { | ||||
|             return json_decode($response->getBody(),true); | ||||
|         }else { | ||||
|             info($response->raw_body); | ||||
| 
 | ||||
|             $this->isSuccessful = false; | ||||
| @ -70,6 +97,26 @@ class CompleteService | ||||
|         } | ||||
| 
 | ||||
|         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() | ||||
|  | ||||
| @ -68,7 +68,6 @@ | ||||
|         "league/fractal": "0.13.*", | ||||
|         "lokielse/omnipay-alipay": "~1.4", | ||||
|         "maatwebsite/excel": "dev-carbon#8b17952", | ||||
|         "mashape/unirest-php": "^3.0.4", | ||||
|         "meebio/omnipay-creditcall": "dev-master", | ||||
|         "meebio/omnipay-secure-trading": "dev-master", | ||||
|         "mfauveau/omnipay-pacnet": "~2.0", | ||||
|  | ||||
| @ -2,7 +2,7 @@ | ||||
| // This is global bootstrap for autoloading | ||||
| 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('permissions_username', 'permissions@example.com'); | ||||
| Fixtures::add('password', 'password'); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user