This commit is contained in:
Romain Neutron
2012-04-26 00:55:53 +02:00
parent edbfff226e
commit ade22295ad
631 changed files with 92375 additions and 101763 deletions

View File

@@ -17,56 +17,54 @@
*/
class Setup_Constraint
{
protected $name;
protected $success;
protected $message;
protected $blocker;
protected $name;
protected $success;
protected $message;
protected $blocker;
public function __construct($name, $success, $message, $blocker = false)
{
$this->name = $name;
$this->success = ! ! $success;
$this->message = $message;
$this->blocker = ! ! $blocker;
public function __construct($name, $success, $message, $blocker = false)
{
$this->name = $name;
$this->success = !!$success;
$this->message = $message;
$this->blocker = !!$blocker;
return $this;
}
return $this;
}
/**
*
* @return string
*/
public function get_name()
{
return $this->name;
}
/**
*
* @return string
*/
public function get_name()
{
return $this->name;
}
/**
*
* @return boolean
*/
public function is_ok()
{
return $this->success;
}
/**
*
* @return boolean
*/
public function is_ok()
{
return $this->success;
}
/**
*
* @return boolean
*/
public function is_blocker()
{
return $this->blocker;
}
/**
*
* @return string
*/
public function get_message()
{
return $this->message;
}
/**
*
* @return boolean
*/
public function is_blocker()
{
return $this->blocker;
}
/**
*
* @return string
*/
public function get_message()
{
return $this->message;
}
}

View File

@@ -17,22 +17,20 @@
*/
class Setup_ConstraintsIterator implements IteratorAggregate
{
protected $constraints = array();
protected $constraints = array();
public function __construct(Array $constraints)
{
$this->constraints = $constraints;
}
public function __construct(Array $constraints)
{
$this->constraints = $constraints;
}
public function add(Setup_Constraint $constraint)
{
$this->constraints[] = $constraint;
}
public function getIterator()
{
return new ArrayIterator($this->constraints);
}
public function add(Setup_Constraint $constraint)
{
$this->constraints[] = $constraint;
}
public function getIterator()
{
return new ArrayIterator($this->constraints);
}
}

View File

@@ -18,30 +18,28 @@
*/
class Setup_Registry implements registryInterface
{
protected $datas = array();
protected $datas = array();
public function get($key, $defaultvalue = null)
{
return isset($this->datas[$key]) ? $this->datas[$key] : $defaultvalue;
}
public function get($key, $defaultvalue = null)
{
return isset($this->datas[$key]) ? $this->datas[$key] : $defaultvalue;
}
public function set($key, $value, $type)
{
$this->datas[$key] = $value;
}
public function set($key, $value, $type)
{
$this->datas[$key] = $value;
}
public function is_set($key)
{
return isset($this->datas[$key]);
}
public function is_set($key)
{
return isset($this->datas[$key]);
}
public function un_set($key)
{
if (isset($this->datas[$key]))
unset($datas[$key]);
return $this;
}
public function un_set($key)
{
if (isset($this->datas[$key]))
unset($datas[$key]);
return $this;
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* This file is part of Phraseanet
*
@@ -19,218 +20,212 @@
*/
class Setup_Upgrade
{
/**
*
* @var appbox
*/
protected $appbox;
/**
*
* @var appbox
*/
protected $appbox;
/**
*
* @var string
*/
protected $message;
/**
*
* @var string
*/
protected $message;
/**
*
* @var int
*/
protected $total_steps = 0;
/**
*
* @var int
*/
protected $total_steps = 0;
/**
*
* @var int
*/
protected $completed_steps = 0;
/**
*
* @var int
*/
protected $completed_steps = 0;
/**
*
* @param appbox $appbox
* @return Setup_Upgrade
*/
public function __construct(appbox &$appbox)
{
if (self::lock_exists())
/**
*
* @param appbox $appbox
* @return Setup_Upgrade
*/
public function __construct(appbox &$appbox)
{
throw new Exception_Setup_UpgradeAlreadyStarted('The upgrade is already started');
if (self::lock_exists()) {
throw new Exception_Setup_UpgradeAlreadyStarted('The upgrade is already started');
}
$this->appbox = $appbox;
if (count(User_Adapter::get_wrong_email_users($appbox)) > 0) {
throw new Exception_Setup_FixBadEmailAddresses('Please fix the database before starting');
}
$this->write_lock();
return $this;
}
$this->appbox = $appbox;
if(count(User_Adapter::get_wrong_email_users($appbox)) > 0)
/**
*
* @return Void
*/
public function __destruct()
{
throw new Exception_Setup_FixBadEmailAddresses('Please fix the database before starting');
self::remove_lock_file();
return;
}
$this->write_lock();
/**
* 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;
}
return $this;
}
/**
*
* @return Void
*/
public function __destruct()
{
self::remove_lock_file();
/**
* 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;
}
return $this;
}
/**
* 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();
/**
* Set the current message
*
* @param string $message
* @return Setup_Upgrade
*/
public function set_current_message($message)
{
$this->message = $message;
$this->write_lock();
return $this;
}
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 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 $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;
}
/**
*
* @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(
/**
*
*
* @return Setup_Upgrade
*/
protected function write_lock()
{
$date_obj = new DateTime();
$dumper = new Symfony\Component\Yaml\Dumper();
$datas = $dumper->dump(
array(
'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
);
'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())
);
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 = array(
'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 $this;
}
return $datas;
}
/**
* 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 = array(
'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;
}
}