couple more minor adjustment to prior commit
[openemr.git] / services / VersionService.php
blob89c64b6952cd15656486b8806572f464e31084de
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
29 /**
30 * Logger used primarily for logging events that are of interest to
31 * developers.
33 private $logger;
35 /**
36 * The version repository to be used for db CRUD operations.
38 private $repository;
40 /**
41 * Default constructor.
43 public function __construct()
45 $this->logger = new \common\logging\Logger("\services\VersionService");
46 $database = \common\database\Connector::Instance();
47 $entityManager = $database->entityManager;
48 $this->repository = $entityManager->getRepository('\entities\Version');
51 /**
52 * Before potentially making any updates to the system, we need to ensure
53 * the version table exists.
55 * @return bool
57 public function doesTableExist()
59 return $this->repository->doesTableExist();
62 /**
63 * @return the sole version entry in the database.
65 public function fetch()
67 $version = $this->repository->findFirst();
69 if (empty($version)) {
70 $this->logger->error("No version found");
71 return null;
74 return $version;
77 /**
78 * Updates the sole version entry in the database. If the release contains
79 * a patch file, also updates the real patch indicator.
81 * @param $version the new version entry.
82 * @return true/false for if the update went through.
84 public function update(Version $version)
86 $this->logger->debug("Updating version entry");
87 if (!$this->canRealPatchBeApplied($version)) {
88 $version->setRealPatch(0);
91 return $this->repository->update($version);
94 /**
95 * @return bool if the release contains a patch file or not.
97 public function canRealPatchBeApplied(Version $version)
99 $this->logger->debug("Determining if a real patch can be applied");
100 //Collected below function call to a variable, since unable to directly include
101 // function calls within empty() in php versions < 5.5 .
102 $version_getrealpatch = $version->getRealPatch();
103 return !empty($version_getrealpatch) && ($version->getRealPatch() != "") && ($version->getRealPatch() > 0);