@@ -80,6 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8080
8181 $ output ->writeln (sprintf ('Imported %s transactions ' , $ offset ));
8282 $ this ->getContainer ()->get ("app.status " )->importTransactionDone ();
83+ $ output ->writeln ("Command completed successfully " );
8384 }
8485
8586
@@ -111,26 +112,27 @@ private function saveTransactions($jsonTransactions)
111112 $ newCnt = 0 ;
112113
113114 foreach ($ jsonTransactions as $ jsonTransaction ) {
114- if ($ transaction = $ transactionRepository ->findOneBy (["transactionId " =>$ jsonTransaction ['transactionId ' ]])) {
115+ if ($ license = $ licenseRepository ->findOneBy (["addonLicenseId " =>$ jsonTransaction ["addonLicenseId " ]])) {
116+ $ this ->locatedExistingLicense = true ;
117+ // TODO: check if license info is changed
118+ } else {
119+ if ($ this ->locatedExistingLicense ) {
120+ // Something weird happens. We already located transaction with existing licence. So either transactions is incorrectly ordered, OR we have bug
121+ // TODO: set flag
122+ throw new \Exception ("Lost license for transaction # " .$ jsonTransaction ['transactionId ' ]);
123+ }
124+ continue ;
125+ }
126+ if ($ transaction = $ transactionRepository ->findOneBy (["license " =>$ license , "transactionId " =>$ jsonTransaction ['transactionId ' ]])) {
115127 // TODO: check if transaction is changed.
116128 } else {
117129 $ newCnt ++;
118130 $ transaction = new Transaction ();
119131 $ transaction ->setTransactionId ($ jsonTransaction ['transactionId ' ]);
132+ $ transaction ->setLicense ($ license );
120133 $ this ->em ->persist ($ transaction );
121134 $ this ->em ->flush ($ transaction );
122- if ($ license = $ licenseRepository ->findOneBy (["addonLicenseId " =>$ jsonTransaction ["addonLicenseId " ]])) {
123- $ this ->locatedExistingLicense = true ;
124- $ transaction ->setLicense ($ license );
125- // TODO: check if license info is changed
126- } else {
127- if ($ this ->locatedExistingLicense ) {
128- // Something weird happens. We already located transaction with existing licence. So either transactions is incorrectly ordered, OR we have bug
129- // TODO: set flag
130- throw new \Exception ("Lost license for transaction # " .$ transaction ->getTransactionId ());
131- }
132- continue ;
133- }
135+
134136 Setter::set ($ jsonTransaction ,$ transaction ,"transactionId " );
135137 if (isset ($ jsonTransaction ["customerDetails " ]["company " ])) {
136138// Pretty weird, but Atlassian provide full company name in transactions list and brief company name for licenses list.
0 commit comments