Add UserSetting entity

This commit is contained in:
Nicolas Le Goff
2013-08-21 18:54:49 +02:00
parent dc0bd4b020
commit 33c4d85116
4 changed files with 292 additions and 1 deletions

View File

@@ -18,7 +18,7 @@ namespace Alchemy\Phrasea\Core;
*/
class Version
{
protected static $number = '3.9.0.a3';
protected static $number = '3.9.0.a4';
protected static $name = 'Diplodocus';
public static function getNumber()

View File

@@ -0,0 +1,191 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Entities;
use Alchemy\Phrasea\Application;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Table(name="UserSettings",
* uniqueConstraints={
* @ORM\UniqueConstraint(name="unique_setting",columns={"usr_id", "name"})
* }
* )
* @ORM\Entity(repositoryClass="Repositories\UserSettingRepository")
*/
class UserSetting
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
private $id;
/**
* @ORM\Column(type="integer", name="usr_id")
*/
private $usrId;
/**
* @ORM\Column(type="string", length=64)
*/
private $name;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $value;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updated;
/**
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @return integer
*/
public function getUsrId()
{
return $this->usrId;
}
/**
* @param integer $usrId
*
* @return UserSetting
*/
public function setUsrId($usrId)
{
$this->usrId = $usrId;
return $this;
}
/**
* @param \Alchemy\Phrasea\Application $app
*
* @return string
*/
public function getUser(Application $app)
{
return \User_Adapter::getInstance($this->usrId, $app);
}
/**
* @param \User_Adapter $user
*
* @return UserSetting
*/
public function setUser(\User_Adapter $user)
{
$this->setUsrId($user->get_id());
return $this;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*
* @return UserSetting
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* @param string $value
*
* @return UserSetting
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* @param \DateTime $created
*
* @return UserSetting
*/
public function setCreated(\DateTime $created)
{
$this->created = $created;
return $this;
}
/**
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* @param \DateTime $updated
*
* @return UserSetting
*/
public function setUpdated(\DateTime $updated)
{
$this->updated = $updated;
return $this;
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Repositories;
use Doctrine\ORM\EntityRepository;
/**
* UserSettingRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class UserSettingRepository extends EntityRepository
{
}

View File

@@ -0,0 +1,85 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 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 Entities\UserSetting;
class patch_3904 implements patchInterface
{
/** @var string */
private $release = '3.9.0.a4';
/** @var array */
private $concern = array(base::APPLICATION_BOX);
/**
* {@inheritdoc}
*/
public function get_release()
{
return $this->release;
}
/**
* {@inheritdoc}
*/
public function require_all_upgrades()
{
return false;
}
/**
* {@inheritdoc}
*/
public function concern()
{
return $this->concern;
}
/**
* {@inheritdoc}
*/
public function apply(base $appbox, Application $app)
{
$conn = $app['phraseanet.appbox']->get_connection();
$sql = 'SELECT * FROM usr_settings';
$stmt = $conn->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
$n = 0;
$em = $app['EM'];
foreach ($rs as $row) {
if (substr($row['prop'], 0, 13) === "notification_") {
continue;
}
$userSetting = new UserSetting();
$userSetting->setName($row['prop']);
$userSetting->setValue($row['value']);
$userSetting->setUsrId($row['usr_id']);
$em->persist($userSetting);
$n++;
if ($n % 1000 === 0) {
$em->flush();
$em->clear();
}
}
$em->flush();
$em->clear();
}
}