示例#1
0
 /**
  * Checks progress of installation
  *
  * @return JsonModel
  */
 public function progressAction()
 {
     $percent = 0;
     $success = false;
     $contents = [];
     $json = new JsonModel();
     // Depending upon the install environment and network latency, there is a possibility that
     // "progress" check request may arrive before the Install POST request. In that case
     // "install.log" file may not be created yet. Check the "install.log" is created before
     // trying to read from it.
     if (!$this->log->logfileExists()) {
         return $json->setVariables(['progress' => $percent, 'success' => true, 'console' => $contents]);
     }
     try {
         $progress = $this->progressFactory->createFromLog($this->log);
         $percent = sprintf('%d', $progress->getRatio() * 100);
         $success = true;
         $contents = $this->log->get();
         if ($this->sampleDataState->hasError()) {
             $json->setVariable('isSampleDataError', true);
         }
     } catch (\Exception $e) {
         $contents = [(string) $e];
     }
     return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]);
 }
示例#2
0
    /**
     * Clear state file
     */
    protected function tearDown()
    {
        $this->filesystem->expects($this->any())->method('getDirectoryWrite')->willReturn($this->writeInterface);
        $this->writeInterface->expects($this->any())->method('openFile')->willReturnSelf($this->absolutePath);

        $this->state->clearState();
    }
 /**
  * @param array $expected
  * @param $withSampleData
  *
  * @dataProvider indexActionDataProvider
  */
 public function testIndexAction($expected, $withSampleData)
 {
     if ($withSampleData) {
         $this->moduleList->expects($this->once())->method('has')->willReturn(true);
         $this->objectManager->expects($this->once())->method('get')->willReturn($this->sampleDataState);
         $this->sampleDataState->expects($this->once())->method('isInstalled')->willReturn($expected['isSampleDataInstalled']);
         $this->sampleDataState->expects($this->once())->method('hasError')->willReturn($expected['isSampleDataErrorInstallation']);
     } else {
         $this->moduleList->expects($this->once())->method('has')->willReturn(false);
         $this->objectManager->expects($this->never())->method('get');
     }
     $this->lists->expects($this->once())->method('getTimezoneList')->willReturn($expected['timezone']);
     $this->lists->expects($this->once())->method('getCurrencyList')->willReturn($expected['currency']);
     $this->lists->expects($this->once())->method('getLocaleList')->willReturn($expected['language']);
     $viewModel = $this->controller->indexAction();
     $this->assertInstanceOf('Zend\\View\\Model\\ViewModel', $viewModel);
     $this->assertTrue($viewModel->terminate());
     $variables = $viewModel->getVariables();
     $this->assertArrayHasKey('timezone', $variables);
     $this->assertArrayHasKey('currency', $variables);
     $this->assertArrayHasKey('language', $variables);
     $this->assertSame($expected, $variables);
 }
示例#4
0
 public function testProgressActionWithSampleDataError()
 {
     $numValue = 42;
     $progress = $this->getMock('\\Magento\\Setup\\Model\\Installer\\Progress', [], [], '', false);
     $progress->expects($this->once())->method('getRatio')->willReturn($numValue);
     $this->progressFactory->expects($this->once())->method('createFromLog')->willReturn($progress);
     $this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true);
     $jsonModel = $this->controller->progressAction();
     $this->assertInstanceOf('\\Zend\\View\\Model\\JsonModel', $jsonModel);
     $variables = $jsonModel->getVariables();
     $this->assertArrayHasKey('success', $variables);
     $this->assertArrayHasKey('console', $variables);
     $this->assertTrue($variables['success']);
     $this->assertTrue($jsonModel->getVariable('isSampleDataError'));
     $this->assertSame(sprintf('%d', $numValue * 100), $variables['progress']);
 }
示例#5
0
 /**
  * Checks progress of installation
  *
  * @return JsonModel
  */
 public function progressAction()
 {
     $percent = 0;
     $success = false;
     $json = new JsonModel();
     try {
         $progress = $this->progressFactory->createFromLog($this->log);
         $percent = sprintf('%d', $progress->getRatio() * 100);
         $success = true;
         $contents = $this->log->get();
         if ($this->sampleDataState->hasError()) {
             $json->setVariable('isSampleDataError', true);
         }
     } catch (\Exception $e) {
         $contents = [(string) $e];
     }
     return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]);
 }
示例#6
0
    public function testInstall()
    {
        $request = [
            ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1',
            ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento',
            ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento',
            ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key',
            ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend',
        ];
        $this->config->expects($this->atLeastOnce())
            ->method('get')
            ->willReturnMap(
                [
                    [ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT, null, true],
                    [ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, null, true],
                ]
            );
        $allModules = ['Foo_One' => [], 'Bar_Two' => []];
        $this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules);
        $setup = $this->getMock('Magento\Setup\Module\Setup', [], [], '', false);
        $table = $this->getMock('Magento\Framework\DB\Ddl\Table', [], [], '', false);
        $connection = $this->getMockForAbstractClass('Magento\Framework\DB\Adapter\AdapterInterface');
        $setup->expects($this->any())->method('getConnection')->willReturn($connection);
        $table->expects($this->any())->method('addColumn')->willReturn($table);
        $table->expects($this->any())->method('setComment')->willReturn($table);
        $table->expects($this->any())->method('addIndex')->willReturn($table);
        $connection->expects($this->any())->method('newTable')->willReturn($table);
        $resource = $this->getMock('Magento\Framework\App\ResourceConnection', [], [], '', false);
        $this->contextMock->expects($this->any())->method('getResources')->willReturn($resource);
        $resource->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
        $dataSetup = $this->getMock('Magento\Setup\Module\DataSetup', [], [], '', false);
        $cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false);
        $cacheManager->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']);
        $cacheManager->expects($this->once())->method('setEnabled')->willReturn(['foo', 'bar']);
        $cacheManager->expects($this->any())->method('clean');
        $appState = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
            'Magento\Framework\App\State'
        );
        $this->setupFactory->expects($this->atLeastOnce())->method('create')->with($resource)->willReturn($setup);
        $this->dataSetupFactory->expects($this->atLeastOnce())->method('create')->willReturn($dataSetup);
        $this->objectManager->expects($this->any())
            ->method('create')
            ->will($this->returnValueMap([
                ['Magento\Framework\App\Cache\Manager', [], $cacheManager],
                ['Magento\Framework\App\State', [], $appState],
            ]));
        $this->objectManager->expects($this->any())
            ->method('get')
            ->will($this->returnValueMap([
                ['Magento\Framework\App\State', $appState],
                ['Magento\Framework\App\Cache\Manager', $cacheManager]
            ]));
        $this->adminFactory->expects($this->once())->method('create')->willReturn(
            $this->getMock('Magento\Setup\Model\AdminAccount', [], [], '', false)
        );
        $this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true);
        $this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn(
            ['responseType' => \Magento\Setup\Controller\ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]
        );

        $this->logger->expects($this->at(0))->method('log')->with('Starting Magento installation:');
        $this->logger->expects($this->at(1))->method('log')->with('File permissions check...');
        $this->logger->expects($this->at(3))->method('log')->with('Required extensions check...');
        // at(2) invokes logMeta()
        $this->logger->expects($this->at(5))->method('log')->with('Enabling Maintenance Mode...');
        // at(4) - logMeta and so on...
        $this->logger->expects($this->at(7))->method('log')->with('Installing deployment configuration...');
        $this->logger->expects($this->at(9))->method('log')->with('Installing database schema:');
        $this->logger->expects($this->at(11))->method('log')->with("Module 'Foo_One':");
        $this->logger->expects($this->at(13))->method('log')->with("Module 'Bar_Two':");
        $this->logger->expects($this->at(15))->method('log')->with('Schema post-updates:');
        $this->logger->expects($this->at(16))->method('log')->with("Module 'Foo_One':");
        $this->logger->expects($this->at(18))->method('log')->with("Module 'Bar_Two':");
        $this->logger->expects($this->at(21))->method('log')->with('Installing user configuration...');
        $this->logger->expects($this->at(23))->method('log')->with('Enabling caches:');
        $this->logger->expects($this->at(27))->method('log')->with('Installing data...');
        $this->logger->expects($this->at(28))->method('log')->with('Data install/update:');
        $this->logger->expects($this->at(29))->method('log')->with("Module 'Foo_One':");
        $this->logger->expects($this->at(31))->method('log')->with("Module 'Bar_Two':");
        $this->logger->expects($this->at(33))->method('log')->with('Data post-updates:');
        $this->logger->expects($this->at(34))->method('log')->with("Module 'Foo_One':");
        $this->logger->expects($this->at(36))->method('log')->with("Module 'Bar_Two':");
        $this->logger->expects($this->at(39))->method('log')->with('Installing admin user...');
        $this->logger->expects($this->at(41))->method('log')->with('Caches clearing:');
        $this->logger->expects($this->at(44))->method('log')->with('Disabling Maintenance Mode:');
        $this->logger->expects($this->at(46))->method('log')->with('Post installation file permissions check...');
        $this->logger->expects($this->at(48))->method('log')->with('Write installation date...');
        $this->logger->expects($this->at(50))->method('logSuccess')->with('Magento installation complete.');
        $this->logger->expects($this->at(52))->method('log')
            ->with('Sample Data is installed with errors. See log file for details');
        $this->object->install($request);
    }
    /**
     * Install Magento application
     *
     * @param \ArrayObject|array $request
     * @return void
     * @throws \LogicException
     */
    public function install($request)
    {
        $script[] = ['File permissions check...', 'checkInstallationFilePermissions', []];
        $script[] = ['Enabling Maintenance Mode...', 'setMaintenanceMode', [1]];
        $script[] = ['Installing deployment configuration...', 'installDeploymentConfig', [$request]];
        if (!empty($request[InstallCommand::INPUT_KEY_CLEANUP_DB])) {
            $script[] = ['Cleaning up database...', 'cleanupDb', []];
        }
        $script[] = ['Installing database schema:', 'installSchema', []];
        $script[] = ['Installing user configuration...', 'installUserConfig', [$request]];
        $script[] = ['Enabling caches:', 'enableCaches', []];
        $script[] = ['Installing data...', 'installDataFixtures', []];
        if (!empty($request[InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX])) {
            $script[] = [
                'Creating sales order increment prefix...',
                'installOrderIncrementPrefix',
                [$request[InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX]],
            ];
        }
        $script[] = ['Installing admin user...', 'installAdminUser', [$request]];
        $script[] = ['Caches clearing:', 'cleanCaches', []];
        $script[] = ['Disabling Maintenance Mode:', 'setMaintenanceMode', [0]];
        $script[] = ['Post installation file permissions check...', 'checkApplicationFilePermissions', []];

        $estimatedModules = $this->createModulesConfig($request, true);
        $total = count($script) + 4 * count(array_filter($estimatedModules));
        $this->progress = new Installer\Progress($total, 0);

        $this->log->log('Starting Magento installation:');

        while (list(, list($message, $method, $params)) = each($script)) {
            $this->log->log($message);
            call_user_func_array([$this, $method], $params);
            $this->logProgress();
        }

        $this->log->logSuccess('Magento installation complete.');
        $this->log->logSuccess(
            'Magento Admin URI: /'
            . $this->deploymentConfig->get(BackendConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME)
        );

        if ($this->progress->getCurrent() != $this->progress->getTotal()) {
            throw new \LogicException('Installation progress did not finish properly.');
        }
        if ($this->sampleDataState->hasError()) {
            $this->log->log('Sample Data is installed with errors. See log file for details');
        }
    }
 /**
  * @inheritdoc
  */
 public function install(Setup\ModuleDataSetupInterface $setup, Setup\ModuleContextInterface $moduleContext)
 {
     $this->state->clearState();
 }