5 * Copyright (C) 2016 Matthew Vita <matthewvita48@gmail.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @author Matthew Vita <matthewvita48@gmail.com>
20 * @link http://www.open-emr.org
23 namespace repositories
;
26 use Doctrine\ORM\EntityRepository
;
28 class VersionRepository
extends EntityRepository
{
30 * Updates the sole version entry in the database. The version
31 * table doesn't use unique keys, so a special merger function
32 * is used to ensure Doctrine doesn't insert a new entry and
33 * only updates the original one.
35 * @param $version the new version entry.
36 * @return true/false for if the update went through.
38 public function update(Version
$version) {
42 $objectToBeUpdated = $this->updateNonKeyedEntityObject($this->findFirst(), $version);
43 $updateInformation = $this->_em
->persist($objectToBeUpdated);
46 } catch (Exception
$e) {}
52 * Finds the sole version entry in the database.
56 public function findFirst() {
57 $results = $this->_em
->getRepository($this->_entityName
)->findAll();
58 if (!empty($results)) {
66 * Uses MySQL-specific check to see if the version table exists.
70 public function doesTableExist() {
71 $query = $this->_em
->getConnection()->prepare("SHOW TABLES LIKE 'version'");
73 $results = $query->fetch();
75 return !empty($results);
79 * Special merger function to ensure Doctrine doesn't insert a new entry and
80 * only updates the original one.
82 * @param $objectToBeUpdated the current entry in the table that needs to be updated.
83 * @param $newObject the new value object.
84 * @return the updated version ready to override the current version entry in the table.
86 private function updateNonKeyedEntityObject(Version
$objectToBeUpdated, Version
$newObject) {
87 if (!empty($objectToBeUpdated)) {
88 $objectToBeUpdated->setAcl($newObject->getAcl());
89 $objectToBeUpdated->setDatabase($newObject->getDatabase());
90 $objectToBeUpdated->setTag($newObject->getTag());
91 $objectToBeUpdated->setRealPatch($newObject->getRealPatch());
92 $objectToBeUpdated->setPatch($newObject->getPatch());
93 $objectToBeUpdated->setMinor($newObject->getMinor());
94 $objectToBeUpdated->setMajor($newObject->getMajor());
96 return $objectToBeUpdated;