Merge pull request #896 for calendar bug fix
[openemr.git] / services / VersionService.php
blob58b41182e7e95952c49e932196c42bd4cda30b94
1 <?php
2 /**
3 * VersionService
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>;.
18 * @package OpenEMR
19 * @author Matthew Vita <matthewvita48@gmail.com>
20 * @link http://www.open-emr.org
23 namespace services;
25 use entities\Version;
27 class VersionService {
28 /**
29 * Logger used primarily for logging events that are of interest to
30 * developers.
32 private $logger;
34 /**
35 * The version repository to be used for db CRUD operations.
37 private $repository;
39 /**
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');
49 /**
50 * Before potentially making any updates to the system, we need to ensure
51 * the version table exists.
53 * @return bool
55 public function doesTableExist() {
56 return $this->repository->doesTableExist();
59 /**
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");
67 return null;
70 return $version;
73 /**
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);
89 /**
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);