Upgrade Commands

This commit is contained in:
Romain Neutron
2012-09-12 14:41:44 +02:00
parent 3e3a3f1bd0
commit 219de0588f
8 changed files with 27 additions and 25 deletions

View File

@@ -51,7 +51,7 @@ class BuildMissingSubdefs extends Command
{
if ($input->getOption('verbose')) {
$handler = new StreamHandler('php://stdout');
$this->container['phraseanet.core']['monolog']->pushHandler($handler);
$this->container['monolog']->pushHandler($handler);
}
$start = microtime(true);
@@ -98,8 +98,8 @@ class BuildMissingSubdefs extends Command
}
if ($todo) {
$record->generate_subdefs($databox, $this->container['phraseanet.core']['monolog'], array($subdef->get_name()));
$this->container['phraseanet.core']['monolog']->addInfo("generate " . $subdef->get_name() . " for record " . $record->get_record_id());
$record->generate_subdefs($databox, $this->container, array($subdef->get_name()));
$this->container['monolog']->addInfo("generate " . $subdef->get_name() . " for record " . $record->get_record_id());
$n ++;
}
}
@@ -109,11 +109,11 @@ class BuildMissingSubdefs extends Command
}
}
$this->container['phraseanet.core']['monolog']->addInfo($n . " subdefs done");
$this->container['monolog']->addInfo($n . " subdefs done");
$stop = microtime(true);
$duration = $stop - $start;
$this->container['phraseanet.core']['monolog']->addInfo(sprintf("process took %s, (%f sd/s.)", $this->getFormattedDuration($duration), round($n / $duration, 3)));
$this->container['monolog']->addInfo(sprintf("process took %s, (%f sd/s.)", $this->getFormattedDuration($duration), round($n / $duration, 3)));
return;
}

View File

@@ -56,7 +56,7 @@ abstract class Command extends SymfoCommand
public function checkSetup()
{
if ($this->requireSetup()) {
if ($this->container['phraseanet.core'] && ! $this->container['phraseanet.core']->getConfiguration()->isInstalled()) {
if (!$this->container['phraseanet.configuration']->isInstalled()) {
throw new \RuntimeException('Phraseanet must be set-up');
}
}
@@ -71,7 +71,7 @@ abstract class Command extends SymfoCommand
if ($input->getOption('verbose')) {
$handler = new StreamHandler('php://stdout');
$this->container['phraseanet.core']['monolog']->pushHandler($handler);
$this->container['monolog']->pushHandler($handler);
}
return $this->doExecute($input, $output);

View File

@@ -72,6 +72,6 @@ class CreateCollection extends Command
}
}
\User_Adapter::reset_sys_admins_rights();
\User_Adapter::reset_sys_admins_rights($this->container);
}
}

View File

@@ -69,7 +69,7 @@ class RecordAdd extends Command
throw new \InvalidArgumentException(sprintf('File %s does not exists', $file));
}
$media = $this->container['phraseanet.core']['mediavorus']->guess(new \SplFileInfo($file));
$media = $this->container['mediavorus']->guess($file);
$dialog = $this->getHelperSet()->get('dialog');
@@ -87,15 +87,15 @@ class RecordAdd extends Command
if ($input->getOption('in-place') !== '1') {
$originalName = pathinfo($file, PATHINFO_BASENAME);
$tempfile = tempnam(sys_get_temp_dir(), 'addrecord') . '.' . pathinfo($file, PATHINFO_EXTENSION);
$this->container['phraseanet.core']['monolog']->addInfo(sprintf('copy file from `%s` to temporary `%s`', $file, $tempfile));
$this->container['monolog']->addInfo(sprintf('copy file from `%s` to temporary `%s`', $file, $tempfile));
$this->container['filesystem']->copy($file, $tempfile, true);
$file = $tempfile;
$media = $this->container['phraseanet.core']['mediavorus']->guess(new \SplFileInfo($file));
$media = $this->container['mediavorus']->guess($file);
}
$file = new File($media, $collection, $originalName);
$session = new LazaretSession();
$this->container['phraseanet.core']['EM']->persist($session);
$this->container['EM']->persist($session);
$forceBehavior = null;
@@ -118,7 +118,7 @@ class RecordAdd extends Command
$elementCreated = $element;
};
$this->container['phraseanet.core']['border-manager']->process($session, $file, $callback, $forceBehavior);
$this->container['border-manager']->process($session, $file, $callback, $forceBehavior);
if ($elementCreated instanceof \record_adapter) {
$output->writeln(
@@ -133,7 +133,7 @@ class RecordAdd extends Command
}
if ($tempfile) {
$this->container['phraseanet.core']['monolog']->addInfo(sprintf('Remove temporary file `%s`', $tempfile));
$this->container['monolog']->addInfo(sprintf('Remove temporary file `%s`', $tempfile));
$this->container['filesystem']->remove($tempfile);
}

View File

@@ -84,7 +84,7 @@ class RescanTechnicalDatas extends Command
foreach ($rs as $row) {
$record = $databox->get_record($row['record_id']);
$record->insertTechnicalDatas();
$record->insertTechnicalDatas($this->getService('mediavorus'));
unset($record);
$output->write("\r" . $n . " records done");
$n ++;

View File

@@ -123,16 +123,16 @@ class Step31 implements DatasUpgraderInterface
$uuid = \uuid::generate_v4();
try {
$media = $this->app['phraseanet.core']['mediavorus']->guess(new \SplFileInfo($pathfile));
$media = $this->app['mediavorus']->guess($pathfile);
$collection = \collection::get_from_coll_id($databox, (int) $record['coll_id']);
$file = new File($media, $collection);
$uuid = $file->getUUID(true, true);
$sha256 = $file->getSha256();
$this->app['phraseanet.core']['monolog']->addInfo(sprintf("Upgrading record %d with uuid %s", $record['record_id'], $uuid));
$this->app['monolog']->addInfo(sprintf("Upgrading record %d with uuid %s", $record['record_id'], $uuid));
} catch (\Exception $e) {
$this->app['phraseanet.core']['monolog']->addError(sprintf("Uuid upgrade for record %s failed", $record['record_id']));
$this->app['monolog']->addError(sprintf("Uuid upgrade for record %s failed", $record['record_id']));
}
$sql = 'UPDATE record SET uuid = :uuid, sha256 = :sha256 WHERE record_id = :record_id';

View File

@@ -76,22 +76,22 @@ class Step35 implements DatasUpgraderInterface
$stmt->execute(array(':record_id' => $row['record_id']));
try {
$record = new \record_adapter($databox->get_sbas_id(), $row['record_id']);
$record = new \record_adapter($app, $databox->get_sbas_id(), $row['record_id']);
} catch (\Exception $e) {
$this->app['phraseanet.core']['monolog']->addError(sprintf("Unable to load record %d on databox %d : %s", $record->get_record_id(), $record->get_sbas_id(), $record->get_sbas_id(), $e->getMessage()));
$this->app['monolog']->addError(sprintf("Unable to load record %d on databox %d : %s", $record->get_record_id(), $record->get_sbas_id(), $record->get_sbas_id(), $e->getMessage()));
continue;
}
try {
$this->updateMetadatas($record, $row['xml']);
} catch (Exception $e) {
$this->app['phraseanet.core']['monolog']->addError(sprintf("Error while upgrading metadatas for record %d on databox %d : %s", $record->get_record_id(), $record->get_sbas_id(), $e->getMessage()));
$this->app['monolog']->addError(sprintf("Error while upgrading metadatas for record %d on databox %d : %s", $record->get_record_id(), $record->get_sbas_id(), $e->getMessage()));
}
try {
$record->set_binary_status($row['status']);
} catch (Exception $e) {
$this->app['phraseanet.core']['monolog']->addError(sprintf("Error while upgrading status for record %d on databox %d : %s", $record->get_record_id(), $record->get_sbas_id(), $e->getMessage()));
$this->app['monolog']->addError(sprintf("Error while upgrading status for record %d on databox %d : %s", $record->get_record_id(), $record->get_sbas_id(), $e->getMessage()));
}
unset($record);
}

View File

@@ -3,6 +3,8 @@
namespace Alchemy\Phrasea\Command;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Command\Upgrade\Step31;
use Alchemy\Phrasea\Command\Upgrade\Step35;
class UpgradeDBDatasTest extends \PHPUnit_Framework_TestCase
{
@@ -38,7 +40,7 @@ class UpgradeDBDatasTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(), $this->object->getUpgrades());
$upgrades = array(
new Upgrade\Step31(new Application())
new Step31(new Application())
);
$this->object->setUpgrades($upgrades);
$this->assertEquals($upgrades, $this->object->getUpgrades());
@@ -51,12 +53,12 @@ class UpgradeDBDatasTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals(array(), $this->object->getUpgrades());
$step31 = new Upgrade\Step31(new Application());
$step31 = new Step31(new Application());
$this->object->addUpgrade($step31);
$this->assertEquals(array($step31), $this->object->getUpgrades());
$step35 = new Upgrade\Step35(new Application());
$step35 = new Step35(new Application());
$this->object->addUpgrade($step35);
$this->assertEquals(array($step31, $step35), $this->object->getUpgrades());