revert attr() in path that was breaking admin calendar
[openemr.git] / services / VersionService.php
blob174269c482e3694910e47bec8b1e2555d5e77523
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 OpenEMR\Services;
25 use OpenEMR\Common\Database\Connector;
26 use OpenEMR\Common\Logging\Logger;
27 use OpenEMR\Entities\Version;
29 class VersionService
31 /**
32 * Logger used primarily for logging events that are of interest to
33 * developers.
35 private $logger;
37 /**
38 * The version repository to be used for db CRUD operations.
40 private $repository;
42 /**
43 * Default constructor.
45 public function __construct()
47 $this->logger = new Logger("\OpenEMR\Services\VersionService");
48 $database = Connector::Instance();
49 $entityManager = $database->entityManager;
50 $this->repository = $entityManager->getRepository('\OpenEMR\Entities\Version');
53 /**
54 * Before potentially making any updates to the system, we need to ensure
55 * the version table exists.
57 * @return bool
59 public function doesTableExist()
61 return $this->repository->doesTableExist();
64 /**
65 * @return the sole version entry in the database.
67 public function fetch()
69 $version = $this->repository->findFirst();
71 if (empty($version)) {
72 $this->logger->error("No version found");
73 return null;
76 return $version;
79 /**
80 * Updates the sole version entry in the database. If the release contains
81 * a patch file, also updates the real patch indicator.
83 * @param $version the new version entry.
84 * @return true/false for if the update went through.
86 public function update(Version $version)
88 $this->logger->debug("Updating version entry");
89 if (!$this->canRealPatchBeApplied($version)) {
90 $version->setRealPatch(0);
93 return $this->repository->update($version);
96 /**
97 * @return bool if the release contains a patch file or not.
99 public function canRealPatchBeApplied(Version $version)
101 $this->logger->debug("Determining if a real patch can be applied");
102 //Collected below function call to a variable, since unable to directly include
103 // function calls within empty() in php versions < 5.5 .
104 $version_getrealpatch = $version->getRealPatch();
105 return !empty($version_getrealpatch) && ($version->getRealPatch() != "") && ($version->getRealPatch() > 0);