mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-11-04 05:15:39 +00:00 
			
		
		
		
	Code for Spectre.
This commit is contained in:
		@@ -114,7 +114,7 @@ class JobStatusController extends Controller
 | 
			
		||||
    public function start(ImportJob $importJob): JsonResponse
 | 
			
		||||
    {
 | 
			
		||||
        // catch impossible status:
 | 
			
		||||
        $allowed = ['ready_to_run', 'need_job_config'];
 | 
			
		||||
        $allowed = ['ready_to_run', 'need_job_config','error']; // todo remove error
 | 
			
		||||
 | 
			
		||||
        if (null !== $importJob && !\in_array($importJob->status, $allowed, true)) {
 | 
			
		||||
            Log::error('Job is not ready.');
 | 
			
		||||
 
 | 
			
		||||
@@ -54,17 +54,20 @@ class SpectreRoutine implements RoutineInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function run(): void
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->importJob->status === 'ready_to_run') {
 | 
			
		||||
 | 
			
		||||
        $valid = ['ready_to_run','error']; // should be only ready_to_run
 | 
			
		||||
        if(in_array($this->importJob->status, $valid)) {
 | 
			
		||||
            switch ($this->importJob->stage) {
 | 
			
		||||
                default:
 | 
			
		||||
                    throw new FireflyException(sprintf('SpectreRoutine cannot handle stage "%s".', $this->importJob->stage));
 | 
			
		||||
                case 'new':
 | 
			
		||||
                case 'authenticate':
 | 
			
		||||
                    /** @var StageNewHandler $handler */
 | 
			
		||||
                    $handler = app(StageNewHandler::class);
 | 
			
		||||
                    $handler->setImportJob($this->importJob);
 | 
			
		||||
                    $handler->run();
 | 
			
		||||
                    $this->repository->setStage($this->importJob, 'authenticate');
 | 
			
		||||
                    var_dump($this->repository->getConfiguration($this->importJob));
 | 
			
		||||
                    exit;
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -59,6 +59,7 @@ class StageNewHandler
 | 
			
		||||
     */
 | 
			
		||||
    public function run(): void
 | 
			
		||||
    {
 | 
			
		||||
        Log::debug('Now in stageNewHandler::run()');
 | 
			
		||||
        $customer = $this->getCustomer();
 | 
			
		||||
        // get token using customer.
 | 
			
		||||
        $token = $this->getToken($customer);
 | 
			
		||||
@@ -83,12 +84,15 @@ class StageNewHandler
 | 
			
		||||
     */
 | 
			
		||||
    private function getCustomer(): Customer
 | 
			
		||||
    {
 | 
			
		||||
        Log::debug('Now in stageNewHandler::getCustomer()');
 | 
			
		||||
        $customer = $this->getExistingCustomer();
 | 
			
		||||
        if (null === $customer) {
 | 
			
		||||
            Log::debug('The customer is NULL, will fire a newCustomerRequest.');
 | 
			
		||||
            $newCustomerRequest = new NewCustomerRequest($this->importJob->user);
 | 
			
		||||
            $customer           = $newCustomerRequest->getCustomer();
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        Log::debug('The customer is not null.');
 | 
			
		||||
 | 
			
		||||
        return $customer;
 | 
			
		||||
    }
 | 
			
		||||
@@ -99,14 +103,18 @@ class StageNewHandler
 | 
			
		||||
     */
 | 
			
		||||
    private function getExistingCustomer(): ?Customer
 | 
			
		||||
    {
 | 
			
		||||
        Log::debug('Now in getExistingCustomer()');
 | 
			
		||||
        $customer           = null;
 | 
			
		||||
        $getCustomerRequest = new ListCustomersRequest($this->importJob->user);
 | 
			
		||||
        $getCustomerRequest->call();
 | 
			
		||||
        $customers = $getCustomerRequest->getCustomers();
 | 
			
		||||
 | 
			
		||||
        Log::debug(sprintf('Found %d customer(s)', \count($customers)));
 | 
			
		||||
        /** @var Customer $current */
 | 
			
		||||
        foreach ($customers as $current) {
 | 
			
		||||
            if ('default_ff3_customer' === $current->getIdentifier()) {
 | 
			
		||||
                $customer = $current;
 | 
			
		||||
                Log::debug('Found the correct customer.');
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -122,6 +130,7 @@ class StageNewHandler
 | 
			
		||||
     */
 | 
			
		||||
    private function getToken(Customer $customer): Token
 | 
			
		||||
    {
 | 
			
		||||
        Log::debug('Now in getToken()');
 | 
			
		||||
        $request = new CreateTokenRequest($this->importJob->user);
 | 
			
		||||
        $request->setUri(route('import.job.status.index', [$this->importJob->key]));
 | 
			
		||||
        $request->setCustomer($customer);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user