using OemrUI class in Fees > Fee Sheet, Billing, Payment, Checkout, Batch Payments...
[openemr.git] / services / VersionService.php
blob04603b1a35f5369331833d88bb47152addb6f3b8
1 <?php
2 /**
3 * VersionService
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Matthew Vita <matthewvita48@gmail.com>
8 * @copyright Copyright (c) 2017 Matthew Vita <matthewvita48@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 namespace OpenEMR\Services;
15 use OpenEMR\Common\Database\Connector;
16 use OpenEMR\Common\Logging\Logger;
17 use OpenEMR\Entities\Version;
19 class VersionService
21 /**
22 * Logger used primarily for logging events that are of interest to
23 * developers.
25 private $logger;
27 /**
28 * The version repository to be used for db CRUD operations.
30 private $repository;
32 /**
33 * Default constructor.
35 public function __construct()
37 $this->logger = new Logger("\OpenEMR\Services\VersionService");
38 $database = Connector::Instance();
39 $entityManager = $database->entityManager;
40 $this->repository = $entityManager->getRepository('\OpenEMR\Entities\Version');
43 /**
44 * Before potentially making any updates to the system, we need to ensure
45 * the version table exists.
47 * @return bool
49 public function doesTableExist()
51 return $this->repository->doesTableExist();
54 /**
55 * @return the sole version entry in the database.
57 public function fetch()
59 $version = $this->repository->findFirst();
61 if (empty($version)) {
62 $this->logger->error("No version found");
63 return null;
66 return $version;
69 /**
70 * Updates the sole version entry in the database. If the release contains
71 * a patch file, also updates the real patch indicator.
73 * @param $version the new version entry.
74 * @return true/false for if the update went through.
76 public function update(Version $version)
78 $this->logger->debug("Updating version entry");
79 if (!$this->canRealPatchBeApplied($version)) {
80 $version->setRealPatch(0);
83 return $this->repository->update($version);
86 /**
87 * @return bool if the release contains a patch file or not.
89 public function canRealPatchBeApplied(Version $version)
91 $this->logger->debug("Determining if a real patch can be applied");
92 //Collected below function call to a variable, since unable to directly include
93 // function calls within empty() in php versions < 5.5 .
94 $version_getrealpatch = $version->getRealPatch();
95 return !empty($version_getrealpatch) && ($version->getRealPatch() != "") && ($version->getRealPatch() > 0);