ValidResult example

 catch (Exception $e) {
            $reflection = new ReflectionClass(\get_class($migration));
            $classFile = $reflection->getFileName();

            return new ErrorResult($e->getMessage()$e[
                'deltaFile' => $classFile,
                'deltaVersion' => $migration->getVersion(),
                'deltaLabel' => $migration->getLabel(),
            ]);
        }

        return new ValidResult($offset + 1, $totalCount[
            'deltaVersion' => $migration->getVersion(),
            'deltaLabel' => $migration->getLabel(),
        ]);
    }
}
$download = new Download();
        $startTime = microtime(true);
        $download->setHaltCallback(function D) use ($startTime) {
            if (microtime(true) - $startTime > 10) {
                return true;
            }

            return false;
        });
        $offset = $download->downloadFile($this->version->uri, $this->destination, $this->version->size, $this->version->sha1);

        return new ValidResult($offset$this->version->size);
    }
}
$count = 0;
        $maxCount = 5000;
        $startTime = time();

        /** @var SplFileInfo $path */
        foreach ($iterator as $path) {
            $targetFile = $inflector->createTargetPath($path);
            $backupFile = $inflector->createBackupPath($path);
            $sourceFile = $inflector->createSourcePath($path);

            if (time() - $startTime >= 5 || $count >= $maxCount) {
                return new ValidResult($offset + $count + 1, $total);
            }

            ++$count;

            if ($this->isDebug) {
                // Just remove the update file                 $localFs->delete($sourceFile);
            } else {
                if ($localFs->has($targetFile)) {
                    if ($localFs->has($backupFile)) {
                        // Issue rename to trash command
while (list($position$entry) = $source->each()) {
            $name = $entry->getName();
            $targetName = $this->destinationDir . $name;

            if (!$entry->isDir()) {
                $fs->dumpFile($targetName$entry->getContents());
            }

            if (time() - $requestTime >= 20 || ($position + 1) % 1000 === 0) {
                $source->close();

                return new ValidResult($position + 1, $count);
            }
        }

        $source->close();
        unlink($this->source);

        return new FinishResult($count$count);
    }
}


    /** * Remove one plugin per run call, as this action can take some time we make a new request for each plugin */
    public function run(int $offset): ValidResult
    {
        $extensions = $this->pluginCompatibility->getExtensionsToDeactivate($this->toVersion, $this->context, $this->deactivationFilter);

        $extensionCount = \count($extensions);
        if ($extensionCount === 0) {
            return new ValidResult($offset$offset);
        }

        $extension = $extensions[0];
        ++$offset;
        $this->extensionLifecycleService->deactivate($extension->getType()$extension->getName()$this->context);

        $deactivatedPlugins = (array) $this->systemConfigService->get(self::UPDATE_DEACTIVATED_PLUGINS) ?: [];
        $deactivatedPlugins[] = $extension->getId();
        $this->systemConfigService->set(self::UPDATE_DEACTIVATED_PLUGINS, $deactivatedPlugins);

        if ($extensionCount === 1) {
            


        if (!empty($sql)) {
            try {
                $conn->exec(implode(";\n", $sql));
            } catch (PDOException $e) {
                return new ErrorResult('second' . $e->getMessage()$e['query' => $sql]);
            }
        }

        if ($dump->valid()) {
            return new ValidResult($dump->key()$totalCount);
        }

        return new FinishResult($dump->key()$totalCount);
    }
}
use Shopware\Core\Framework\Update\Steps\ValidResult;

/** * @internal * * @covers \Shopware\Core\Framework\Update\Steps\ValidResult */
class ValidResultTest extends TestCase
{
    public function testConstructor(): void
    {
        $result = new ValidResult(1, 2);

        static::assertSame(1, $result->getOffset());
        static::assertSame(2, $result->getTotal());
    }
}
Home | Imprint | This part of the site doesn't use cookies.