5 * Copyright (C) 2017 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
27 class VersionService
{
29 * Logger used primarily for logging events that are of interest to
35 * The version repository to be used for db CRUD operations.
40 * Default constructor.
42 public function __construct() {
43 $this->logger
= new \common\logging\
Logger("\services\VersionService");
44 $database = \common\database\Connector
::Instance();
45 $entityManager = $database->entityManager
;
46 $this->repository
= $entityManager->getRepository('\entities\Version');
50 * Before potentially making any updates to the system, we need to ensure
51 * the version table exists.
55 public function doesTableExist() {
56 return $this->repository
->doesTableExist();
60 * @return the sole version entry in the database.
62 public function fetch() {
63 $version = $this->repository
->findFirst();
65 if (empty($version)) {
66 $this->logger
->error("No version found");
74 * Updates the sole version entry in the database. If the release contains
75 * a patch file, also updates the real patch indicator.
77 * @param $version the new version entry.
78 * @return true/false for if the update went through.
80 public function update(Version
$version) {
81 $this->logger
->debug("Updating version entry");
82 if (!$this->canRealPatchBeApplied($version)) {
83 $version->setRealPatch(0);
86 return $this->repository
->update($version);
90 * @return bool if the release contains a patch file or not.
92 public function canRealPatchBeApplied(Version
$version) {
93 $this->logger
->debug("Determining if a real patch can be applied");
94 //Collected below function call to a variable, since unable to directly include
95 // function calls within empty() in php versions < 5.5 .
96 $version_getrealpatch = $version->getRealPatch();
97 return !empty($version_getrealpatch) && ($version->getRealPatch() != "") && ($version->getRealPatch() > 0);