public function testArchive()
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         $this->markTestSkipped();
     }
     $jobName = 'Backup';
     $jobStatus = new \Magento\Update\Status();
     $jobStatus->clear();
     $backupInfo = $this->getMockBuilder('Magento\\Update\\Backup\\BackupInfo')->disableOriginalConstructor()->getMock();
     $backupInfo->expects($this->any())->method('generateBackupFilename')->willReturn($this->backupFilename);
     $backupInfo->expects($this->any())->method('getArchivedDirectory')->willReturn(UPDATER_BP);
     $backupInfo->expects($this->any())->method('getBlacklist')->willReturn(['var/backup', 'vendor', 'app/code']);
     $backupInfo->expects($this->any())->method('getBackupPath')->willReturn($this->backupPath);
     $maintenanceMode = new MaintenanceMode(TESTS_TEMP_DIR . '/maintenanceMode.flag', TESTS_TEMP_DIR . '/maintenanceAddress.flag');
     $jobBackup = new \Magento\Update\Queue\JobBackup($jobName, [], $jobStatus, $maintenanceMode, $backupInfo);
     $this->dirList = scandir($this->backupPath);
     $jobBackup->execute();
     $tmpFiles = array_diff(scandir($this->backupPath), $this->dirList);
     $actualBackupFile = array_pop($tmpFiles);
     $this->assertEquals($this->backupFilename, $actualBackupFile);
     $actualJobStatus = $jobStatus->get();
     $fullBackupFileName = $this->backupPath . $this->backupFilename;
     $this->assertContains(sprintf('Creating backup archive "%s" ...', $fullBackupFileName), $actualJobStatus);
     $this->assertContains(sprintf('Backup archive "%s" has been created.', $fullBackupFileName), $actualJobStatus);
     if (file_exists($this->backupPath . $actualBackupFile)) {
         unlink($this->backupPath . $actualBackupFile);
     }
 }
Example #2
0
 public function testIsUpdateError()
 {
     $status = new \Magento\Update\Status($this->tmpStatusFilePath, $this->tmpStatusLogFilePath, $this->updateInProgressFlagFilePath, $this->updateErrorFlagFilePath);
     $this->assertFalse($status->isUpdateError());
     $this->assertInstanceOf('Magento\\Update\\Status', $status->setUpdateError());
     $this->assertTrue($status->isUpdateError());
     $this->assertInstanceOf('Magento\\Update\\Status', $status->setUpdateError(false));
     $this->assertFalse($status->isUpdateError());
     $this->assertInstanceOf('Magento\\Update\\Status', $status->setUpdateError(true));
     $this->assertTrue($status->isUpdateError());
 }
<?php

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
require_once __DIR__ . '/app/bootstrap.php';
$status = new \Magento\Update\Status();
$statusMessage = $status->get(10);
$isUpdateInProgress = $status->isUpdateInProgress();
/** TODO: Section below is added for demo purposes */
$status->add("Message #" . rand(1, 1000));
if (!$statusMessage) {
    $statusMessage = 'Please wait for job processing to start.';
}
$statusMessage = str_replace("\n", "<br />", $statusMessage);
//$isUpdateInProgress = (bool)rand(0, 1);
/** TODO: End of section added for demo */
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
    /* Ajax request processing */
    echo json_encode(['statusMessage' => $statusMessage, 'isUpdateInProgress' => $isUpdateInProgress]);
} else {
    include __DIR__ . '/app/code/Magento/Update/view/templates/status.phtml';
}
Example #4
0
<?php

/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
require_once __DIR__ . '/app/bootstrap.php';
header('X-Frame-Options: SAMEORIGIN');
header('X-Content-Type-Options: nosniff');
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 8') === false) {
    $xssHeaderValue = '1; mode=block';
} else {
    $xssHeaderValue = '0';
}
header('X-XSS-Protection: ' . $xssHeaderValue);
$status = new \Magento\Update\Status();
$isUpdateInProgress = $status->isUpdateInProgress();
$statusMessage = '';
$statusMessage .= $status->get();
$statusMessage = str_replace("\n", "<br />", $statusMessage);
$queue = new \Magento\Update\Queue();
$pending = !$status->isUpdateInProgress() && !$queue->isEmpty() && !$status->isUpdateError();
if (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO'])) {
    if ($_SERVER['PATH_INFO'] === '/rollback' && file_exists(MAGENTO_BP . '/var/.update_error.flag')) {
        try {
            $queue->clear();
            $backupInfo = new \Magento\Update\Backup\BackupInfo();
            $backupPaths = $backupInfo->getBackupFilePaths();
            if (isset($backupPaths['error'])) {
                $status->add('WARNING: There is a problem with backup files! Performing rollback from these' . ' files may cause the Magento application to be unstable', \Psr\Log\LogLevel::WARNING);
                foreach ($backupPaths['error'] as $error) {
<?php

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
require_once __DIR__ . '/app/bootstrap.php';
$status = new \Magento\Update\Status();
$cronReadinessChecker = new \Magento\Update\CronReadinessCheck();
if (!$cronReadinessChecker->runReadinessCheck()) {
    exit('Cron readiness check failed');
}
if ($status->isUpdateInProgress()) {
    exit('Cron is already in progress...');
}
if ($status->isUpdateError()) {
    exit('There was an error in previous Updater jobs...');
}
$backupDirectory = BACKUP_DIR;
if (!file_exists($backupDirectory)) {
    if (!mkdir($backupDirectory)) {
        $status->add(sprintf('Backup directory "%s" cannot be created.', $backupDirectory));
        exit;
    }
    chmod($backupDirectory, 0770);
}
try {
    $status->setUpdateInProgress();
} catch (\RuntimeException $e) {
    $status->add($e->getMessage());
    exit;
Example #6
0
<?php

/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
require_once __DIR__ . '/app/bootstrap.php';
/**
 * Update cron exit codes
 */
const UPDATE_CRON_NORMAL_EXIT = 0;
const UPDATE_CRON_EXIT_WITH_ERROR = 1;
$status = new \Magento\Update\Status();
$cronReadinessChecker = new \Magento\Update\CronReadinessCheck();
$notification = 'update-cron: Please check var/log/update.log for execution summary.' . PHP_EOL;
if (!$cronReadinessChecker->runReadinessCheck()) {
    print $notification;
    exit(UPDATE_CRON_EXIT_WITH_ERROR);
}
if ($status->isUpdateInProgress()) {
    $status->add('Update is already in progress.', \Psr\Log\LogLevel::WARNING);
    print $notification;
    exit(UPDATE_CRON_EXIT_WITH_ERROR);
}
if ($status->isUpdateError()) {
    $status->add('There was an error in previous Update attempt.');
    print $notification;
    exit(UPDATE_CRON_EXIT_WITH_ERROR);
}
$backupDirectory = BACKUP_DIR;
if (!file_exists($backupDirectory)) {