/** * Merges the dependencies class maps. * * @param $vendor */ private function mergeComposerClassMap($vendor) { if ($composerClassMap = $this->findComposerDirectory($vendor, 'autoload_classmap.php')) { $this->log->debug('Located autoload_classmap.php file', ['path' => $composerClassMap]); $classMap = (require $composerClassMap); if ($classMap) { $this->app->getLoader()->addClassMap($classMap); } } }
public function __invoke(array $data) : array { foreach ($data['prepared'] as $key => $value) { try { $json = json_decode((string) $this->request($value['data'])->getBody(), true); $searchId = $json['search_id']; unset($json); $data['ongoing'][$key] = $value; $data['ongoing'][$key]['data'] = $searchId; unset($data['prepared'][$key]); $this->log->debug('Count has begun', ['date' => $key, 'searchId' => $searchId]); } catch (RequestException $e) { /** * This may happen. Just skip that query and move on. */ $this->log->warning('Count failed to begin', ['message' => $e->getMessage(), 'date' => $key, 'searchId' => $searchId]); } } return $data; }
/** * Execute the job * * @param Log $log * @return void */ public function handle(Log $log) { $log->debug("Handling check job for queue '{$this->queueName}', queued at {$this->startTime}"); $status = QueueStatus::get($this->queueName); if (!$status) { $message = "Queue status was not found in cache, yet queued job ran; is the cache correctly configured?"; $log->error($message); $status = new QueueStatus($this->queueName, QueueStatus::ERROR, false); $status->setMessage($message); $status->setEndTime(); $status->save(); } elseif (!$status->isPending()) { $log->warning("Non-pending status for check for queue '{$this->queueName}' found in the cache; ignoring: " . $status); } elseif (!$status->getStartTime() || $status->getStartTime()->ne($this->startTime)) { $log->warning("Pending status for check for queue '{$this->queueName}' found in the cache with mismatching time (expected {$this->startTime}, found {$status->getStartTime()}); ignoring: " . $status); } else { $log->debug("Successful queue check for queue '{$this->queueName}'"); $status->setStatus(QueueStatus::OK); $status->setEndTime(); $status->save(); } }
/** * */ protected function replayEvents() { $allEvents = $this->getAllEvents(); $this->output->progressStart(count($allEvents)); foreach ($allEvents as $eventRow) { $object = ['class' => str_replace('.', '\\', $eventRow->type), 'payload' => json_decode($eventRow->payload, true)['payload']]; try { $this->dispatcher->dispatch($eventRow->type, $this->serializer->deserialize($object)); } catch (SerializedClassDoesNotExist $e) { if ($this->logger) { $this->logger->debug("Event class does not exist: [{$object['class']}]"); } continue; } } $this->output->progressFinish(); }
/** * Updates a given package. * * This is the wrong method if you are looking * for something like 'composer update'. Look * at the 'configurePackage' method instead. * * @throws ComposerException * @param $packageName * @return mixed */ public function updatePackage($packageName) { if (!$this->packageExists($packageName)) { return false; } $newPackageLocation = $this->resolvePackagePath($packageName); $oldPackageLocation = $this->normalizePath($newPackageLocation . '_{updating_in_progress}'); $installationInstructionsPath = $this->normalizePath($oldPackageLocation . DIRECTORY_SEPARATOR . '_newup_install_instructions'); if ($this->files->exists($oldPackageLocation)) { $this->files->deleteDirectory($oldPackageLocation, false); } $this->files->makeDirectory($oldPackageLocation, 0755, true); $this->files->copyDirectory($newPackageLocation, $oldPackageLocation); $this->files->deleteDirectory($newPackageLocation, false); // Retrieve the old installation instructions that were stored // when the package template was first installed. $installInstructions = $this->files->get($installationInstructionsPath); // Write updated initiated here in case of early failures. $this->writePackageUpdateInitiated($newPackageLocation, $installInstructions); try { $this->addPackage($installInstructions); // Write updated initiated here in case of failures during configuration. $this->writePackageUpdateInitiated($newPackageLocation, $installInstructions); $this->configurePackage($packageName); $this->files->deleteDirectory($oldPackageLocation, false); $this->log->info('Updated package template', ['package' => $packageName]); // If we are at this point of the update process, we can safely assume that // it is okay to remove the update initiated file. $this->removePackageUpdateInitiatedFile($newPackageLocation); return true; } catch (\Exception $e) { // There was an issue updating the package. We will rollback. $this->files->deleteDirectory($newPackageLocation, false); $this->files->makeDirectory($newPackageLocation, 0755, true); $this->files->copyDirectory($oldPackageLocation, $newPackageLocation); $this->files->deleteDirectory($oldPackageLocation, false); $this->log->debug('Package updated failed', ['package' => $packageName, 'message' => $e->getMessage(), 'exception' => $e]); throw new ComposerException('There was an unexpected failure during the package update process.', $e->getCode(), $e); } }
/** * Checks the installation directory to make sure it is ready. * * @throws InvalidInstallationDirectoryException * @throws PackageInstallationException * @param $directory */ private function checkInstallationDirectory($directory) { if ($this->installationAttempts >= $this->breakAtInstallationAttempt) { $this->log->error('Installation directory checks failed at max attempts', ['attempts' => $this->installationAttempts]); throw new PackageInstallationException(null, "The package template could not be installed."); } $files = $this->files->allFiles($directory); $directories = $this->files->directories($directory); if (count($files) == 0 && count($directories) == 0) { return; } $directoriesReadable = true; $filesReadable = true; foreach ($directories as $directory) { if (!$this->files->isReadable($directory)) { $this->log->error('Unreadable directory preventing Composer install', ['directory' => $directory]); $directoriesReadable = false; } } foreach ($files as $file) { if (!$this->files->isReadable($file->getPathname())) { $this->log->error('Unreadable file preventing Composer install', ['file' => $file]); $filesReadable = false; } } if (!$directoriesReadable || !$filesReadable) { $this->log->critical('Unreadable files/directories, cannot proceed with install.'); throw new InvalidInstallationDirectoryException(null, "The installation directory ({$directory}) is not empty and could not be cleared due to a permissions issue. Please manually remove all files from the directory and try again."); } if (!$this->files->isWritable($directory)) { $this->log->critical('Installation directory is not writeable by NewUp. Cannot proceed with install.', ['directory' => $directory, 'permissions' => fileperms($directory)]); throw new InvalidInstallationDirectoryException(null, "The installation directory ({$directory}) is not writeable by the NewUp process."); } // At this point, there is no clear reason why the preparation // did not succeed. Because of this, we will try again. $this->installationAttempts++; $this->log->debug('Installation attempt incremented', ['directory' => $directory, 'attempt' => $this->installationAttempts]); $this->prepareInstallationDirectory($directory); }
/** * @param DomainMessage $domainMessage */ public function handle(DomainMessage $domainMessage) { $name = explode('.', $domainMessage->getType()); $name = preg_replace('/(?!^)[A-Z]{2,}(?=[A-Z][a-z])|[A-Z][a-z]/', ' $0', end($name)); $this->log->debug(trim(ucwords($name)) . " ({$domainMessage->getType()})"); }
/** * Marks the last started query as stopped. This can be used for timing of queries. * @return void */ public function stopQuery() { $this->logger->debug($this->getQuery(), [$this->getExecutionTime()]); }