mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Remove unused code
This commit is contained in:
@@ -117,13 +117,10 @@ class Databoxes implements ControllerProviderInterface
|
||||
break;
|
||||
}
|
||||
|
||||
$upgrader = new \Setup_Upgrade($app);
|
||||
|
||||
return $app['twig']->render('admin/databases.html.twig', [
|
||||
'files' => new \DirectoryIterator($app['root.path'] . '/lib/conf.d/data_templates'),
|
||||
'sbas' => $sbas,
|
||||
'error_msg' => $errorMsg,
|
||||
'recommendations' => $upgrader->getRecommendations(),
|
||||
'advices' => $request->query->get('advices', []),
|
||||
'reloadTree' => (Boolean) $request->query->get('reload-tree'),
|
||||
]);
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Setup\Version\MailChecker;
|
||||
use Symfony\Component\Yaml\Dumper;
|
||||
|
||||
class Setup_Upgrade
|
||||
{
|
||||
@@ -18,31 +19,13 @@ class Setup_Upgrade
|
||||
*
|
||||
* @var appbox
|
||||
*/
|
||||
protected $appbox;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $message;
|
||||
private $appbox;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $recommendations = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $total_steps = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $completed_steps = 0;
|
||||
private $recommendations = [];
|
||||
|
||||
public function __construct(Application $app, $force = false)
|
||||
{
|
||||
@@ -77,48 +60,6 @@ class Setup_Upgrade
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add steps to do to the counter
|
||||
*
|
||||
* @param int $how_many
|
||||
* @return Setup_Upgrade
|
||||
*/
|
||||
public function add_steps($how_many)
|
||||
{
|
||||
$this->total_steps += (int) $how_many;
|
||||
$this->write_lock();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add completed steps to the counter
|
||||
*
|
||||
* @param int $how_many
|
||||
* @return Setup_Upgrade
|
||||
*/
|
||||
public function add_steps_complete($how_many)
|
||||
{
|
||||
$this->completed_steps += (int) $how_many;
|
||||
$this->write_lock();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current message
|
||||
*
|
||||
* @param string $message
|
||||
* @return Setup_Upgrade
|
||||
*/
|
||||
public function set_current_message($message)
|
||||
{
|
||||
$this->message = $message;
|
||||
$this->write_lock();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $recommendation
|
||||
@@ -139,37 +80,18 @@ class Setup_Upgrade
|
||||
return $this->recommendations;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
protected function get_percentage()
|
||||
{
|
||||
if ($this->total_steps === 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return round(max(min(($this->completed_steps / $this->total_steps), 1), 0), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return Setup_Upgrade
|
||||
*/
|
||||
protected function write_lock()
|
||||
private function write_lock()
|
||||
{
|
||||
$date_obj = new DateTime();
|
||||
$dumper = new Symfony\Component\Yaml\Dumper();
|
||||
$datas = $dumper->dump(
|
||||
[
|
||||
'percentage' => $this->get_percentage()
|
||||
, 'total_steps' => $this->total_steps
|
||||
, 'completed_steps' => $this->completed_steps
|
||||
, 'message' => $this->message
|
||||
, 'last_update' => $date_obj->format(DATE_ATOM)
|
||||
], 1
|
||||
);
|
||||
$date_obj = new \DateTime();
|
||||
$dumper = new Dumper();
|
||||
$datas = $dumper->dump([
|
||||
'last_update' => $date_obj->format(DATE_ATOM),
|
||||
], 1);
|
||||
|
||||
if (!file_put_contents(self::get_lock_file(), $datas))
|
||||
throw new Exception_Setup_CannotWriteLockFile(
|
||||
@@ -184,7 +106,7 @@ class Setup_Upgrade
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected static function lock_exists()
|
||||
private static function lock_exists()
|
||||
{
|
||||
clearstatcache();
|
||||
|
||||
@@ -196,7 +118,7 @@ class Setup_Upgrade
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_lock_file()
|
||||
private static function get_lock_file()
|
||||
{
|
||||
return __DIR__ . '/../../../tmp/upgrade.lock';
|
||||
}
|
||||
@@ -205,7 +127,7 @@ class Setup_Upgrade
|
||||
*
|
||||
* @return Void
|
||||
*/
|
||||
protected static function remove_lock_file()
|
||||
private static function remove_lock_file()
|
||||
{
|
||||
if (self::lock_exists()) {
|
||||
unlink(self::get_lock_file());
|
||||
@@ -213,42 +135,4 @@ class Setup_Upgrade
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns an array containing datas about the Upgrade Status.
|
||||
* Contains the following keys :
|
||||
* - active : (booolean) tells if there's a current upgrade
|
||||
* - percentage : (float) a number between 0 and 1 of the current progress
|
||||
* - total_steps : (int) total steps
|
||||
* - completed_steps : (int) current complete steps
|
||||
* - message : (string) a message
|
||||
* - last_update : (string) last update in ATOM format
|
||||
*
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public static function get_status()
|
||||
{
|
||||
$active = self::lock_exists();
|
||||
|
||||
$datas = [
|
||||
'active' => $active
|
||||
, 'percentage' => 1
|
||||
, 'total_steps' => 0
|
||||
, 'completed_steps' => 0
|
||||
, 'message' => null
|
||||
, 'last_update' => null
|
||||
];
|
||||
|
||||
if ($active) {
|
||||
$parser = new Symfony\Component\Yaml\Parser();
|
||||
$datas = array_merge(
|
||||
$datas
|
||||
, $parser->parse(file_get_contents(self::get_lock_file()))
|
||||
);
|
||||
}
|
||||
|
||||
return $datas;
|
||||
}
|
||||
}
|
||||
|
@@ -282,29 +282,11 @@ class appbox extends base
|
||||
{
|
||||
$from_version = $this->get_version();
|
||||
|
||||
$upgrader->add_steps(7 + count($this->get_databoxes()));
|
||||
|
||||
/**
|
||||
* Step 1
|
||||
*/
|
||||
$upgrader->set_current_message($this->app->trans('Flushing cache'));
|
||||
|
||||
$app['phraseanet.cache-service']->flushAll();
|
||||
|
||||
$upgrader->add_steps_complete(1);
|
||||
|
||||
$upgrader->set_current_message($this->app->trans('Creating new tables'));
|
||||
|
||||
// Executes stuff before applying patches
|
||||
$app['phraseanet.pre-schema-upgrader']->apply($app);
|
||||
|
||||
$upgrader->add_steps_complete(1);
|
||||
|
||||
/**
|
||||
* Step 2
|
||||
*/
|
||||
$upgrader->set_current_message($this->app->trans('Purging directories'));
|
||||
|
||||
$finder = new Finder();
|
||||
$finder->in([
|
||||
$this->app['root.path'] . '/tmp/cache_minify/',
|
||||
@@ -322,13 +304,6 @@ class appbox extends base
|
||||
$app['filesystem']->remove($file);
|
||||
}
|
||||
|
||||
$upgrader->add_steps_complete(1);
|
||||
|
||||
/**
|
||||
* Step 5
|
||||
*/
|
||||
$upgrader->set_current_message($this->app->trans('Copying files'));
|
||||
|
||||
foreach ([
|
||||
'config/custom_files/' => 'www/custom/',
|
||||
'config/minilogos/' => 'www/custom/minilogos/',
|
||||
@@ -339,37 +314,13 @@ class appbox extends base
|
||||
$app['filesystem']->mirror($this->app['root.path'] . '/' . $source, $this->app['root.path'] . '/' . $target);
|
||||
}
|
||||
|
||||
$upgrader->add_steps_complete(1);
|
||||
$advices = $this->upgradeDB(true, $app);
|
||||
|
||||
$advices = [];
|
||||
|
||||
/**
|
||||
* Step 6
|
||||
*/
|
||||
$upgrader->set_current_message($this->app->trans('Upgrading appbox'));
|
||||
$advices = $this->upgradeDB(true, $upgrader, $app);
|
||||
$upgrader->add_steps_complete(1);
|
||||
|
||||
/**
|
||||
* Step 7
|
||||
*/
|
||||
foreach ($this->get_databoxes() as $s) {
|
||||
$upgrader->set_current_message($this->app->trans('Upgrading %databox_name%', ['%databox_name%' => $s->get_label($this->app['locale'])]));
|
||||
$advices = array_merge($advices, $s->upgradeDB(true, $upgrader, $app));
|
||||
$upgrader->add_steps_complete(1);
|
||||
$advices = array_merge($advices, $s->upgradeDB(true, $app));
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 8
|
||||
*/
|
||||
$upgrader->set_current_message($this->app->trans('Post upgrade'));
|
||||
$this->post_upgrade($upgrader, $app);
|
||||
$upgrader->add_steps_complete(1);
|
||||
|
||||
/**
|
||||
* Step 9
|
||||
*/
|
||||
$upgrader->set_current_message($this->app->trans('Flushing cache'));
|
||||
$this->post_upgrade($app);
|
||||
|
||||
$app['phraseanet.cache-service']->flushAll();
|
||||
|
||||
@@ -379,8 +330,6 @@ class appbox extends base
|
||||
$tool->updateSchema($metas, true);
|
||||
}
|
||||
|
||||
$upgrader->add_steps_complete(1);
|
||||
|
||||
if (version::lt($from_version, '3.1')) {
|
||||
$upgrader->addRecommendation($app->trans('Your install requires data migration, please execute the following command'), 'bin/setup system:upgrade-datas --from=3.1');
|
||||
} elseif (version::lt($from_version, '3.5')) {
|
||||
@@ -395,17 +344,14 @@ class appbox extends base
|
||||
return $advices;
|
||||
}
|
||||
|
||||
protected function post_upgrade(Setup_Upgrade $upgrader, Application $app)
|
||||
protected function post_upgrade(Application $app)
|
||||
{
|
||||
$upgrader->add_steps(1 + count($this->get_databoxes()));
|
||||
$this->apply_patches($this->get_version(), $app['phraseanet.version']->getNumber(), true, $upgrader, $app);
|
||||
$this->apply_patches($this->get_version(), $app['phraseanet.version']->getNumber(), true, $app);
|
||||
$this->setVersion($app['phraseanet.version']);
|
||||
$upgrader->add_steps_complete(1);
|
||||
|
||||
foreach ($this->get_databoxes() as $databox) {
|
||||
$databox->apply_patches($databox->get_version(), $app['phraseanet.version']->getNumber(), true, $upgrader, $app);
|
||||
$databox->apply_patches($databox->get_version(), $app['phraseanet.version']->getNumber(), true, $app);
|
||||
$databox->setVersion($app['phraseanet.version']);
|
||||
$upgrader->add_steps_complete(1);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@@ -231,7 +231,7 @@ abstract class base implements cache_cacheableInterface
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
protected function upgradeDb($apply_patches, Setup_Upgrade $upgrader, Application $app)
|
||||
protected function upgradeDb($apply_patches, Application $app)
|
||||
{
|
||||
$recommends = [];
|
||||
|
||||
@@ -243,8 +243,6 @@ abstract class base implements cache_cacheableInterface
|
||||
$allTables[(string) $table['name']] = $table;
|
||||
}
|
||||
|
||||
$upgrader->add_steps(count($allTables) + 1);
|
||||
|
||||
$sql = "SHOW TABLE STATUS";
|
||||
$stmt = $this->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
@@ -291,8 +289,6 @@ abstract class base implements cache_cacheableInterface
|
||||
foreach ($rs as $row) {
|
||||
$tname = $row["Name"];
|
||||
if (isset($allTables[$tname])) {
|
||||
$upgrader->set_current_message($app->trans('Updating table %table_name%', ['%table_name%' => $tname]));
|
||||
|
||||
$engine = strtolower(trim($allTables[$tname]->engine));
|
||||
$ref_engine = strtolower($row['Engine']);
|
||||
|
||||
@@ -313,7 +309,6 @@ abstract class base implements cache_cacheableInterface
|
||||
$ret = self::upgradeTable($allTables[$tname]);
|
||||
$recommends = array_merge($recommends, $ret);
|
||||
unset($allTables[$tname]);
|
||||
$upgrader->add_steps_complete(1);
|
||||
} elseif ( ! in_array($tname, $ORMTables)) {
|
||||
$recommends[] = [
|
||||
'message' => 'Une table pourrait etre supprime',
|
||||
@@ -323,17 +318,13 @@ abstract class base implements cache_cacheableInterface
|
||||
}
|
||||
|
||||
foreach ($allTables as $tname => $table) {
|
||||
$upgrader->set_current_message($app->trans('Creating table %table_name%', ['%table_name%' => $table]));
|
||||
$this->createTable($table);
|
||||
$upgrader->add_steps_complete(1);
|
||||
}
|
||||
$current_version = $this->get_version();
|
||||
|
||||
$upgrader->set_current_message($app->trans('Applying patches on %databox_name%', ['%databox_name%' => $this->get_dbname()]));
|
||||
if ($apply_patches) {
|
||||
$this->apply_patches($current_version, $app['phraseanet.version']->getNumber(), false, $upgrader, $app);
|
||||
$this->apply_patches($current_version, $app['phraseanet.version']->getNumber(), false, $app);
|
||||
}
|
||||
$upgrader->add_steps_complete(1);
|
||||
|
||||
return $recommends;
|
||||
}
|
||||
@@ -762,7 +753,7 @@ abstract class base implements cache_cacheableInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
protected function apply_patches($from, $to, $post_process, Setup_Upgrade $upgrader, Application $app)
|
||||
protected function apply_patches($from, $to, $post_process, Application $app)
|
||||
{
|
||||
if (version::eq($from, $to)) {
|
||||
return true;
|
||||
@@ -770,8 +761,6 @@ abstract class base implements cache_cacheableInterface
|
||||
|
||||
$list_patches = [];
|
||||
|
||||
$upgrader->add_steps(1)->set_current_message($app->trans('Looking for patches'));
|
||||
|
||||
$iterator = new DirectoryIterator($this->app['root.path'] . '/lib/classes/patch/');
|
||||
|
||||
foreach ($iterator as $fileinfo) {
|
||||
@@ -809,10 +798,6 @@ abstract class base implements cache_cacheableInterface
|
||||
}
|
||||
}
|
||||
|
||||
$upgrader->add_steps_complete(1)
|
||||
->add_steps(count($list_patches))
|
||||
->set_current_message($app->trans('Applying patches on %databox_name%', ['%databox_name%' => $this->get_dbname()]));
|
||||
|
||||
uasort($list_patches, function (\patchInterface $patch1, \patchInterface $patch2) {
|
||||
return version::lt($patch1->get_release(), $patch2->get_release()) ? -1 : 1;
|
||||
});
|
||||
@@ -846,8 +831,6 @@ abstract class base implements cache_cacheableInterface
|
||||
if (false === $patch->apply($this, $app)) {
|
||||
$success = false;
|
||||
}
|
||||
|
||||
$upgrader->add_steps_complete(1);
|
||||
}
|
||||
|
||||
return $success;
|
||||
|
@@ -53,15 +53,6 @@
|
||||
<p>{{ 'update::Votre version est a jour :' | trans }} {{ app['phraseanet.version'].getNumber() }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% if recommendations | length > 0%}
|
||||
{% for recommendation in recommendations %}
|
||||
<p>{{ recommendation['0'] }}</p>
|
||||
<pre>
|
||||
<blockquote>{{ recommendation['1'] }}</blockquote>
|
||||
</pre>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if advices | length > 0 %}
|
||||
<b>{{ 'Propositions de modifications des tables' | trans }}</b>
|
||||
{% for advice in advices %}
|
||||
|
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Setup_UpgradeTest extends \PhraseanetTestCase
|
||||
{
|
||||
/**
|
||||
* @var Setup_Upgrade
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->object = new Setup_Upgrade(self::$DI['app']);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test__destruct()
|
||||
{
|
||||
$this->assertFileExists(Setup_Upgrade::get_lock_file());
|
||||
unset($this->object);
|
||||
$this->assertFileNotExists(Setup_Upgrade::get_lock_file());
|
||||
}
|
||||
|
||||
public function testAdd_steps()
|
||||
{
|
||||
$this->check_percentage(1, 0, 0);
|
||||
$this->object->add_steps(1);
|
||||
$this->check_percentage(0, 1, 0);
|
||||
$this->object->add_steps('lsdf');
|
||||
$this->check_percentage(0, 1, 0);
|
||||
$this->object->add_steps(20);
|
||||
$this->check_percentage(0, 21, 0);
|
||||
$this->object->add_steps(-5);
|
||||
$this->check_percentage(0, 16, 0);
|
||||
}
|
||||
|
||||
private function check_percentage($percent, $total, $complete)
|
||||
{
|
||||
$datas = $this->object->get_status();
|
||||
$this->assertArrayHasKey('completed_steps', $datas);
|
||||
$this->assertArrayHasKey('total_steps', $datas);
|
||||
$this->assertArrayHasKey('percentage', $datas);
|
||||
$this->assertArrayHasKey('last_update', $datas);
|
||||
$this->assertDateAtom($datas['last_update']);
|
||||
$this->assertEquals($percent, $datas['percentage']);
|
||||
$this->assertEquals($total, $datas['total_steps']);
|
||||
$this->assertEquals($complete, $datas['completed_steps']);
|
||||
}
|
||||
|
||||
public function testAdd_steps_complete()
|
||||
{
|
||||
$this->check_percentage(1, 0, 0);
|
||||
$this->object->add_steps(1)->add_steps_complete(1);
|
||||
$this->check_percentage(1, 1, 1);
|
||||
$this->object->add_steps(20)->add_steps_complete(20);
|
||||
$this->check_percentage(1, 21, 21);
|
||||
$this->object->add_steps(20);
|
||||
$this->check_percentage(round(21 / 41, 2), 41, 21);
|
||||
$this->object->add_steps_complete(40);
|
||||
$this->check_percentage(1, 41, 61);
|
||||
}
|
||||
|
||||
public function testSet_current_message()
|
||||
{
|
||||
$message = 'ZOubid èèè\\';
|
||||
$this->object->set_current_message($message);
|
||||
|
||||
$datas = $this->object->get_status();
|
||||
$this->assertArrayHasKey('message', $datas);
|
||||
$this->assertEquals($message, $datas['message']);
|
||||
}
|
||||
|
||||
public function testGet_status()
|
||||
{
|
||||
$datas = $this->object->get_status();
|
||||
$this->assertTrue(is_array($datas));
|
||||
$this->assertArrayHasKey('active', $datas);
|
||||
$this->assertArrayHasKey('percentage', $datas);
|
||||
$this->assertArrayHasKey('total_steps', $datas);
|
||||
$this->assertArrayHasKey('completed_steps', $datas);
|
||||
$this->assertArrayHasKey('message', $datas);
|
||||
$this->assertArrayHasKey('last_update', $datas);
|
||||
$this->assertDateAtom($datas['last_update']);
|
||||
}
|
||||
}
|
2
tmp/translations/.gitignore
vendored
Normal file
2
tmp/translations/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
Reference in New Issue
Block a user