mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-09 02:54:26 +00:00

Conflicts: lib/Alchemy/Phrasea/Command/Developer/JavascriptBuilder.php lib/Alchemy/Phrasea/Controller/Prod/Basket.php lib/Alchemy/Phrasea/Core/Provider/TaskManagerServiceProvider.php lib/classes/Exception/Feed/ItemNotFound.php lib/classes/Exception/Feed/PublisherNotFound.php lib/classes/Feed/Abstract.php lib/classes/Feed/Adapter.php lib/classes/Feed/Aggregate.php lib/classes/Feed/Collection.php lib/classes/Feed/CollectionInterface.php lib/classes/Feed/Entry/Adapter.php lib/classes/Feed/Entry/Collection.php lib/classes/Feed/Entry/Interface.php lib/classes/Feed/Entry/Item.php lib/classes/Feed/Entry/ItemInterface.php lib/classes/Feed/Interface.php lib/classes/Feed/Link.php lib/classes/Feed/LinkInterface.php lib/classes/Feed/Publisher/Adapter.php lib/classes/Feed/Publisher/Interface.php lib/classes/Feed/Token.php lib/classes/Feed/TokenAggregate.php lib/classes/Feed/XML/Abstract.php lib/classes/Feed/XML/Atom.php lib/classes/Feed/XML/Cooliris.php lib/classes/Feed/XML/Interface.php lib/classes/Feed/XML/RSS.php lib/classes/Feed/XML/RSS/ImageInterface.php lib/classes/http/request.php lib/classes/module/console/schedulerStart.php lib/classes/module/console/schedulerState.php lib/classes/module/console/schedulerStop.php lib/classes/module/console/taskState.php lib/classes/module/console/tasklist.php lib/classes/module/console/taskrun.php lib/classes/registry.php lib/classes/registryInterface.php lib/classes/set/order.php lib/classes/system/url.php lib/classes/task/Scheduler.php lib/classes/task/appboxAbstract.php lib/classes/task/databoxAbstract.php lib/classes/task/manager.php lib/classes/task/period/RecordMover.php lib/classes/task/period/apibridge.php lib/classes/task/period/archive.php lib/classes/task/period/cindexer.php lib/classes/task/period/emptyColl.php lib/classes/task/period/ftp.php lib/classes/task/period/ftpPull.php lib/classes/task/period/subdef.php lib/classes/task/period/test.php lib/classes/task/period/writemeta.php lib/conf.d/PhraseaFixture/AbstractWZ.php lib/conf.d/PhraseaFixture/Basket/LoadFiveBaskets.php lib/conf.d/PhraseaFixture/Basket/LoadOneBasket.php lib/conf.d/PhraseaFixture/Basket/LoadOneBasketEnv.php lib/conf.d/PhraseaFixture/Lazaret/LoadOneFile.php lib/conf.d/PhraseaFixture/Story/LoadOneStory.php lib/conf.d/PhraseaFixture/UsrLists/ListAbstract.php lib/conf.d/PhraseaFixture/UsrLists/UsrList.php lib/conf.d/PhraseaFixture/UsrLists/UsrListEntry.php lib/conf.d/PhraseaFixture/UsrLists/UsrListOwner.php lib/conf.d/PhraseaFixture/ValidationParticipant/LoadOneParticipant.php lib/conf.d/PhraseaFixture/ValidationParticipant/LoadParticipantWithSession.php lib/conf.d/PhraseaFixture/ValidationSession/LoadOneValidationSession.php
255 lines
5.4 KiB
PHP
255 lines
5.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2014 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
use Alchemy\Phrasea\Application;
|
|
use Alchemy\Phrasea\Setup\Version\MailChecker;
|
|
|
|
class Setup_Upgrade
|
|
{
|
|
/**
|
|
*
|
|
* @var appbox
|
|
*/
|
|
protected $appbox;
|
|
|
|
/**
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $message;
|
|
|
|
/**
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $recommendations = [];
|
|
|
|
/**
|
|
*
|
|
* @var int
|
|
*/
|
|
protected $total_steps = 0;
|
|
|
|
/**
|
|
*
|
|
* @var int
|
|
*/
|
|
protected $completed_steps = 0;
|
|
|
|
public function __construct(Application $app, $force = false)
|
|
{
|
|
if ($force) {
|
|
self::remove_lock_file();
|
|
}
|
|
|
|
if (self::lock_exists()) {
|
|
throw new Exception_Setup_UpgradeAlreadyStarted('The upgrade is already started');
|
|
}
|
|
|
|
$this->appbox = $app['phraseanet.appbox'];
|
|
|
|
if (version_compare($this->appbox->get_version(), '3.9', '<')
|
|
&& count(MailChecker::getWrongEmailUsers($app)) > 0) {
|
|
throw new \Exception_Setup_FixBadEmailAddresses('Please fix the database before starting');
|
|
}
|
|
|
|
$this->write_lock();
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return Void
|
|
*/
|
|
public function __destruct()
|
|
{
|
|
self::remove_lock_file();
|
|
|
|
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
|
|
* @param type $command
|
|
*/
|
|
public function addRecommendation($recommendation, $command = null)
|
|
{
|
|
$this->recommendations[] = [$recommendation, $command];
|
|
}
|
|
|
|
/**
|
|
* Return an array of recommendations
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getRecommendations()
|
|
{
|
|
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()
|
|
{
|
|
$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
|
|
);
|
|
|
|
if (!file_put_contents(self::get_lock_file(), $datas))
|
|
throw new Exception_Setup_CannotWriteLockFile(
|
|
sprintf('Cannot write lock file to %s', self::get_lock_file())
|
|
);
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Returns true if the file exists
|
|
*
|
|
* @return boolean
|
|
*/
|
|
protected static function lock_exists()
|
|
{
|
|
clearstatcache();
|
|
|
|
return file_exists(self::get_lock_file());
|
|
}
|
|
|
|
/**
|
|
* Return the path fil to the lock file
|
|
*
|
|
* @return string
|
|
*/
|
|
public static function get_lock_file()
|
|
{
|
|
return __DIR__ . '/../../../tmp/upgrade.lock';
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return Void
|
|
*/
|
|
protected static function remove_lock_file()
|
|
{
|
|
if (self::lock_exists()) {
|
|
unlink(self::get_lock_file());
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|