php - Symfony2 + Doctrine2 not updating in my database -
php - Symfony2 + Doctrine2 not updating in my database -
i have api in symfony2, in adding , deleting items not issue, however, updating doesn't throw me errors relevent row in database not updated!
my controller method:
/* * @route("/complete/uid/{storeuid}", * name = "media_complete" * ) * * @method({"get"}) * * @param string $storeuid - uid store has completed downloading * * @return response */ public function downloadcompleteaction($storeuid) { $response = $this->getnewjsonresponse(); $em = $this->getdoctrine()->getmanager(); $repo = $em->getrepository("simplysmartuhdprobundle:machine"); seek { //get machine db $machine = $repo->findoneby(array( "uid" => $storeuid )); //set download completed $machine->setstatus(machine::status_download_complete); $em->persist($machine); $em->flush(); $response->setstatuscode(200); } grab (\exception $e) { //if there error, grab exception set status 500 , homecoming json exception error $error = array("message" => $e->getmessage()); $response->setcontent(json_encode($error)); $response->setstatuscode(500); } homecoming $response; }
my entity: namespace simplysmart\uhdprobundle\entity; utilize doctrine\common\collections\arraycollection; utilize doctrine\orm\mapping orm; utilize simplysmart\uhdprobundle\entity\store; /** * machine * * @orm\table(name="machines", uniqueconstraints={@orm\uniqueconstraint(name="uid", columns={"uid"})}) * @orm\entity */ class machine { const status_no_feed = 0; const status_requires_download = 1; const status_download_in_progress = 2; const status_download_complete = 3; /** * array of available statuses * * @var array */ static public $statuses = array( self::status_no_feed, self::status_requires_download, self::status_download_in_progress, self::status_download_complete ); /** * @var string * * @orm\column(name="uid", type="string", length=50, nullable=false) */ private $uid; /** * @var string * * @orm\column(name="storecode", type="string", length=10, nullable=false) */ private $storecode; /** * @var string * * @orm\column(name="description", type="string", length=100, nullable=true) */ private $description; /** * @var boolean * * @orm\column(name="status", type="boolean", nullable=false) */ private $status; /** * @var boolean * * @orm\column(name="onlinestatus", type="boolean", nullable=false) */ private $onlinestatus; /** * @var string * * @orm\column(name="version", type="string", length=10, nullable=false) */ private $version; /** * @var \datetime * * @orm\column(name="timestamp", type="datetime", nullable=false) */ private $timestamp; /** * @orm\manytoone(targetentity="simplysmart\uhdprobundle\entity\store", inversedby="machines") * @orm\joincolumn(name="storecode", referencedcolumnname="code") */ protected $store; /** * @orm\manytomany(targetentity="simplysmart\uhdprobundle\entity\feed", inversedby="machines") * @orm\jointable(joincolumns={@orm\joincolumn(name="machine_id", referencedcolumnname="machid")}, * inversejoincolumns={@orm\joincolumn(name="feed_id", referencedcolumnname="feedid")} * ) * */ protected $feeds; /** * @var integer * * @orm\column(name="machid", type="integer") * @orm\id * @orm\generatedvalue(strategy="identity") */ private $machid; /** * */ public function __construct() { $this->feeds = new arraycollection(); } /** * @return string */ public function getdescription() { homecoming $this->description; } /** * @param string $description * * @return $this */ public function setdescription($description) { $this->description = $description; homecoming $this; } /** * @return string */ public function getfeedtype() { homecoming $this->feedtype; } /** * @param string $feedtype * * @return $this */ public function setfeedtype($feedtype) { $this->feedtype = $feedtype; homecoming $this; } /** * @return int */ public function getmachid() { homecoming $this->machid; } /** * @param int $machid * * @return $this */ public function setmachid($machid) { $this->machid = $machid; homecoming $this; } /** * @return boolean */ public function isonlinestatus() { homecoming $this->onlinestatus; } /** * @param boolean $onlinestatus * * @return $this */ public function setonlinestatus($onlinestatus) { $this->onlinestatus = $onlinestatus; homecoming $this; } /** * @return boolean */ public function isstatus() { homecoming $this->status; } /** * @param boolean $status * * @throws \exception if invalid status given * * @return $this */ public function setstatus($status) { if (in_array($status, self::$statuses)) { $this->status = $status; } else { throw new \exception("invalid status given"); } homecoming $this; } /** * @return string */ public function getstorecode() { homecoming $this->storecode; } /** * @param string $storecode * * @return $this */ public function setstorecode($storecode) { $this->storecode = $storecode; homecoming $this; } /** * @return \datetime */ public function gettimestamp() { homecoming $this->timestamp; } /** * @param \datetime $timestamp * * @return $this */ public function settimestamp($timestamp) { $this->timestamp = $timestamp; homecoming $this; } /** * @return string */ public function getuid() { homecoming $this->uid; } /** * @param string $uid * * @return $this */ public function setuid($uid) { $this->uid = $uid; homecoming $this; } /** * @return string */ public function getversion() { homecoming $this->version; } /** * @param string $version * * @return $this */ public function setversion($version) { $this->version = $version; homecoming $this; } /** * status * * @return boolean */ public function getstatus() { homecoming $this->status; } /** * onlinestatus * * @return boolean */ public function getonlinestatus() { homecoming $this->onlinestatus; } /** * set store * * @param \simplysmart\uhdprobundle\entity\store $store * @return machine */ public function setstore(\simplysmart\uhdprobundle\entity\store $store = null) { $this->store = $store; homecoming $this; } /** * store * * @return \simplysmart\uhdprobundle\entity\store */ public function getstore() { homecoming $this->store; } /** * method generate , set new uid * * @return $this */ public function generatenewuid() { $date = new \datetime("utc"); $uid = "u"; $uid .= $date->format("u"); $uid .= 'r'.rand(0,100); $this->setuid($uid); homecoming $this; } /** * add together feeds * * @param \simplysmart\uhdprobundle\entity\feed $feeds * @return machine */ public function addfeed(\simplysmart\uhdprobundle\entity\feed $feeds) { $this->feeds[] = $feeds; homecoming $this; } /** * remove feeds * * @param \simplysmart\uhdprobundle\entity\feed $feeds */ public function removefeed(\simplysmart\uhdprobundle\entity\feed $feeds) { $this->feeds->removeelement($feeds); } /** * feeds * * @return \doctrine\common\collections\collection */ public function getfeeds() { homecoming $this->feeds; } }
i aware when updating entity shouldn't need utilize $em->persist($machine), removing doesn't seem create difference.
the part grinding gears, when go on profiler, appears ran queries expected!
just realised i've been finish idiot , issue status set boolean field in entity, updating, setting 1!
php symfony2 doctrine2
Comments
Post a Comment