Skip to content

Commit

Permalink
Merge pull request #1375 from NextDom/develop
Browse files Browse the repository at this point in the history
0.5.0-RC1
  • Loading branch information
Sylvaner authored Sep 25, 2019
2 parents 9f948ae + 29cd12f commit 15e58ff
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: php
php:
- 7.1
- 7.2
services:
- docker
before_install:
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# NextDom Core Changelog
---
## 0.5.0-RC0

> ***Release Date : 23/09/2019***
>
> ***Statut : Release candidate
* Amélioration de la migration depuis Jeedom
* Possibilité de commander les scénarios depuis le dashboard
* Déplacement du code du core
* Amélioration de compatibilité PHP > 7.2 et Debian Buster
* Correction de bugs
* Correction de l'affichage des updates du Core
* Mise à jour des dépendances

## 0.4.2
> ***Release Date : 13/09/2019***
>
Expand Down
2 changes: 1 addition & 1 deletion assets/config/Nextdom_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.2
0.5.0-RC0
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions core/class/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public static function cron5()
PluginManager::cron5();
}

public static function cron10()
{
PluginManager::cron10();
}

public static function cron15()
{
PluginManager::cron15();
Expand Down
35 changes: 28 additions & 7 deletions src/Managers/ConsistencyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,18 @@ class ConsistencyManager
'power' => array('key' => 'power', 'name' => 'Puissance', 'calcul' => 'sum', 'icon' => '<i class="fa fa-bolt"></i>', 'unit' => 'W', 'allowDisplayZero' => false),
);

/**
* Start consistency check of the system
*
* @throws CoreException
*/
public static function checkConsistency()
{
try {
self::ensureConfiguration();
CronManager::clean();
self::deleteDeprecatedCrons();
self::ensureCrons();
self::removeDeprecatedCrons();
self::checkAllDefaultCrons();
self::cleanWidgetCache();
self::saveObjects();
self::resetCommandsActionID();
Expand All @@ -73,6 +78,10 @@ public static function checkConsistency()
}
}

/**
* TODO: ???
* @throws \Exception
*/
private static function ensureConfiguration()
{
$summary = ConfigManager::byKey("object:summary");
Expand All @@ -86,7 +95,13 @@ private static function ensureConfiguration()
}
}

private static function deleteDeprecatedCrons()
/**
* Remove deprecated cron task
*
* @throws CoreException
* @throws \ReflectionException
*/
private static function removeDeprecatedCrons()
{
$cronTasksToRemove = [
['target_class' => 'nextdom', 'action' => 'persist'],
Expand All @@ -104,7 +119,10 @@ private static function deleteDeprecatedCrons()
}
}

private static function ensureCrons()
/**
* Check if all default cron task are present and add it
*/
private static function checkAllDefaultCrons()
{
foreach (self::getDefaultCrons() as $c_class => $c_data) {
foreach ($c_data as $c_name => $c_config) {
Expand Down Expand Up @@ -262,14 +280,17 @@ private static function resetCommandsActionID()
}
}

/**
* Check if user.function.class.php has been deletedd
*/
private static function ensureUserFunctionExists()
{
$source = sprintf("%s/data/php/user.function.class.sample.php", NEXTDOM_DATA);
$baseFile = sprintf("%s/data/php/user.function.class.sample.php", NEXTDOM_DATA);
$dest = sprintf("%s/data/php/user.function.class.php", NEXTDOM_DATA);

if ((false == file_exists($dest)) &&
(true == file_exists($source))) {
copy($source, $dest);
(true == file_exists($baseFile))) {
copy($baseFile, $dest);
}
}
}
2 changes: 1 addition & 1 deletion src/Managers/ScenarioManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public static function check($event = null, $forceSyncMode = false)
* @return array|mixed|null [] Liste des scénarios
* @throws \Exception
*/
public static function byTrigger(string $cmdId, $onlyEnabled = true)
public static function byTrigger($cmdId, $onlyEnabled = true)
{
$values = array('cmd_id' => '%#' . $cmdId . '#%');
$sql = 'SELECT ' . DBHelper::buildField(self::DB_CLASS_NAME) . '
Expand Down
5 changes: 5 additions & 0 deletions src/Repo/RepoApt.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public static function checkUpdate(&$targetUpdate)
$targetUpdate->save();
}
}
else {
$targetUpdate->setSource('github');
RepoGitHub::checkUpdate($targetUpdate);
$result = true;
}
}
return $result;
}
Expand Down
56 changes: 40 additions & 16 deletions src/Repo/RepoGitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use NextDom\Helpers\NextDomHelper;
use NextDom\Helpers\SystemHelper;
use NextDom\Managers\ConfigManager;
use NextDom\Model\Entity\Update;

require_once __DIR__ . '/../../core/php/core.inc.php';

Expand Down Expand Up @@ -78,39 +79,62 @@ class RepoGitHub

/* * ***********************Méthodes statiques*************************** */

public static function checkUpdate(&$_update)
/**
* @param Update $targetUpdate
*/
public static function checkUpdate(&$targetUpdate)
{
if (is_array($_update)) {
if (count($_update) < 1) {
if (is_array($targetUpdate)) {
if (count($targetUpdate) < 1) {
return;
}
foreach ($_update as $update) {
foreach ($targetUpdate as $update) {
self::checkUpdate($update);
}
return;
}
$client = self::getGithubClient();
// Check if core data is correct and change type or repository if necessary
if ($targetUpdate->getType() === 'core') {
exec('cd ' . NEXTDOM_ROOT . ' && git rev-parse --abbrev-ref HEAD 2> /dev/null', $currentBranch);
if (is_array($currentBranch) && count($currentBranch) > 0) {
$targetUpdate->setConfiguration('version', $currentBranch[0]);
$targetUpdate->save();
}
elseif (!is_dir(NEXTDOM_ROOT . '/.git')) {
$targetUpdate->setSource('apt');
$targetUpdate->save();
RepoApt::checkUpdate($targetUpdate);
return;
}
}
try {
$branch = $client->api('repo')->branches($_update->getConfiguration('user'), $_update->getConfiguration('repository'), $_update->getConfiguration('version', 'master'));
$branch = $client->api('repo')->branches($targetUpdate->getConfiguration('user'), $targetUpdate->getConfiguration('repository'), $targetUpdate->getConfiguration('version', 'master'));
} catch (\Exception $e) {
$_update->setRemoteVersion('repository not found');
$_update->setStatus('ok');
$_update->save();
$targetUpdate->setRemoteVersion('repository not found');
$targetUpdate->setStatus('ok');
$targetUpdate->save();
return;
}
if (!isset($branch['commit']) || !isset($branch['commit']['sha'])) {
$_update->setRemoteVersion('error');
$_update->setStatus('ok');
$_update->save();
$targetUpdate->setRemoteVersion('error');
$targetUpdate->setStatus('ok');
$targetUpdate->save();
return;
}
$_update->setRemoteVersion($branch['commit']['sha']);
if ($branch['commit']['sha'] != $_update->getLocalVersion()) {
$_update->setStatus('update');
$targetUpdate->setRemoteVersion($branch['commit']['sha']);
// Read local version
exec('cd ' . NEXTDOM_ROOT . ' && git rev-parse HEAD 2> /dev/null', $localVersion);
if (is_array($localVersion) && count($localVersion) > 0) {
$targetUpdate->setLocalVersion($localVersion[0]);
}
// Compare
if ($branch['commit']['sha'] != $targetUpdate->getLocalVersion()) {
$targetUpdate->setStatus('update');
} else {
$_update->setStatus('ok');
$targetUpdate->setStatus('ok');
}
$_update->save();
$targetUpdate->save();
}

public static function getGithubClient()
Expand Down

0 comments on commit 15e58ff

Please sign in to comment.