@@ -1375,184 +1375,188 @@ public static function cleanDatabase() {
1375
1375
}
1376
1376
1377
1377
public static function cleanFileSytemRight () {
1378
+ self ::cleanFileSystemRight ();
1379
+ }
1380
+
1381
+ public static function cleanFileSystemRight () {
1378
1382
$ cmd = system::getCmdSudo () . 'chown -R ' . system::get ('www-uid ' ) . ': ' . system::get ('www-gid ' ) . ' ' . __DIR__ . '/../../*; ' ;
1379
1383
$ cmd .= system::getCmdSudo () . 'chmod 775 -R ' . __DIR__ . '/../../*; ' ;
1380
1384
$ cmd .= system::getCmdSudo () . 'find ' . __DIR__ . '/../../log -type f -exec chmod 665 {} +; ' ;
1381
- $ cmd .= system::getCmdSudo () . 'chmod 775 -R ' . __DIR__ . '/../../.* ; ' ;
1382
- exec ($ cmd );
1383
- }
1385
+ $ cmd .= system::getCmdSudo () . 'chmod 775 -R ' . __DIR__ . '/../../.* ; ' ;
1386
+ exec ($ cmd );
1387
+ }
1384
1388
1385
- public static function checkSpaceLeft ($ _dir = null ) {
1386
- if ($ _dir == null ) {
1387
- $ path = __DIR__ . '/../../ ' ;
1388
- } else {
1389
- $ path = $ _dir ;
1390
- }
1391
- return round (disk_free_space ($ path ) / disk_total_space ($ path ) * 100 );
1389
+ public static function checkSpaceLeft ($ _dir = null ) {
1390
+ if ($ _dir == null ) {
1391
+ $ path = __DIR__ . '/../../ ' ;
1392
+ } else {
1393
+ $ path = $ _dir ;
1392
1394
}
1395
+ return round (disk_free_space ($ path ) / disk_total_space ($ path ) * 100 );
1396
+ }
1393
1397
1394
- public static function getTmpFolder ($ _plugin = null ) {
1395
- $ return = '/ ' . trim (config::byKey ('folder::tmp ' ), '/ ' );
1396
- if ($ _plugin !== null ) {
1397
- $ return .= '/ ' . $ _plugin ;
1398
- }
1399
- if (!file_exists ($ return )) {
1400
- mkdir ($ return , 0774 , true );
1401
- $ cmd = system::getCmdSudo () . 'chown -R ' . system::get ('www-uid ' ) . ': ' . system::get ('www-gid ' ) . ' ' . $ return . '; ' ;
1402
- com_shell::execute ($ cmd );
1403
- }
1404
- return $ return ;
1398
+ public static function getTmpFolder ($ _plugin = null ) {
1399
+ $ return = '/ ' . trim (config::byKey ('folder::tmp ' ), '/ ' );
1400
+ if ($ _plugin !== null ) {
1401
+ $ return .= '/ ' . $ _plugin ;
1402
+ }
1403
+ if (!file_exists ($ return )) {
1404
+ mkdir ($ return , 0774 , true );
1405
+ $ cmd = system::getCmdSudo () . 'chown -R ' . system::get ('www-uid ' ) . ': ' . system::get ('www-gid ' ) . ' ' . $ return . '; ' ;
1406
+ com_shell::execute ($ cmd );
1405
1407
}
1408
+ return $ return ;
1409
+ }
1406
1410
1407
- /* * ******************hardware management*************************** */
1411
+ /* * ******************hardware management*************************** */
1408
1412
1409
- public static function getHardwareKey () {
1410
- $ return = config::byKey ('jeedom::installKey ' );
1411
- if ($ return == '' ) {
1412
- $ return = substr (sha512 (microtime () . config::genKey ()), 0 , 63 );
1413
- config::save ('jeedom::installKey ' , $ return );
1414
- }
1415
- return $ return ;
1413
+ public static function getHardwareKey () {
1414
+ $ return = config::byKey ('jeedom::installKey ' );
1415
+ if ($ return == '' ) {
1416
+ $ return = substr (sha512 (microtime () . config::genKey ()), 0 , 63 );
1417
+ config::save ('jeedom::installKey ' , $ return );
1416
1418
}
1419
+ return $ return ;
1420
+ }
1417
1421
1418
- public static function getHardwareName () {
1419
- if (config::byKey ('hardware_name ' ) != '' ) {
1420
- return config::byKey ('hardware_name ' );
1421
- }
1422
- $ result = 'diy ' ;
1423
- $ uname = shell_exec ('uname -a ' );
1424
- if (file_exists ('/.dockerinit ' )) {
1425
- $ result = 'docker ' ;
1426
- } else if (file_exists ('/usr/bin/raspi-config ' )) {
1427
- $ result = 'rpi ' ;
1428
- $ hardware_revision = strtolower (shell_exec ('cat /proc/cpuinfo | grep Revision ' ));
1429
- global $ JEEDOM_RPI_HARDWARE ;
1430
- foreach ($ JEEDOM_RPI_HARDWARE as $ key => $ values ) {
1431
- foreach ($ values as $ value ) {
1432
- if (strpos ($ hardware_revision ,$ value ) !== false ){
1433
- $ result = $ key ;
1434
- }
1422
+ public static function getHardwareName () {
1423
+ if (config::byKey ('hardware_name ' ) != '' ) {
1424
+ return config::byKey ('hardware_name ' );
1425
+ }
1426
+ $ result = 'diy ' ;
1427
+ $ uname = shell_exec ('uname -a ' );
1428
+ if (file_exists ('/.dockerinit ' )) {
1429
+ $ result = 'docker ' ;
1430
+ } else if (file_exists ('/usr/bin/raspi-config ' )) {
1431
+ $ result = 'rpi ' ;
1432
+ $ hardware_revision = strtolower (shell_exec ('cat /proc/cpuinfo | grep Revision ' ));
1433
+ global $ JEEDOM_RPI_HARDWARE ;
1434
+ foreach ($ JEEDOM_RPI_HARDWARE as $ key => $ values ) {
1435
+ foreach ($ values as $ value ) {
1436
+ if (strpos ($ hardware_revision ,$ value ) !== false ){
1437
+ $ result = $ key ;
1435
1438
}
1436
1439
}
1437
- } else if (strpos ($ uname , 'cubox ' ) !== false || strpos ($ uname , 'imx6 ' ) !== false || file_exists ('/media/boot/multiboot/meson64_odroidc2.dtb.linux ' )) {
1438
- $ result = 'miniplus ' ;
1439
- } else if (file_exists ('/usr/bin/grille-pain ' )) {
1440
- $ result = 'freeboxDelta ' ;
1441
1440
}
1442
- if (file_exists ('/media/boot/multiboot/meson64_odroidc2.dtb.linux ' )) {
1443
- $ result = 'smart ' ;
1444
- }
1445
- config::save ('hardware_name ' , $ result );
1446
- return config::byKey ('hardware_name ' );
1441
+ } else if (strpos ($ uname , 'cubox ' ) !== false || strpos ($ uname , 'imx6 ' ) !== false || file_exists ('/media/boot/multiboot/meson64_odroidc2.dtb.linux ' )) {
1442
+ $ result = 'miniplus ' ;
1443
+ } else if (file_exists ('/usr/bin/grille-pain ' )) {
1444
+ $ result = 'freeboxDelta ' ;
1447
1445
}
1446
+ if (file_exists ('/media/boot/multiboot/meson64_odroidc2.dtb.linux ' )) {
1447
+ $ result = 'smart ' ;
1448
+ }
1449
+ config::save ('hardware_name ' , $ result );
1450
+ return config::byKey ('hardware_name ' );
1451
+ }
1448
1452
1449
- public static function isCapable ($ _function , $ _forceRefresh = false ) {
1450
- global $ JEEDOM_COMPATIBILIY_CONFIG ;
1451
- if ($ _function == 'sudo ' ) {
1452
- if (!$ _forceRefresh ) {
1453
- $ cache = cache::byKey ('jeedom::isCapable::sudo ' );
1454
- if ($ cache ->getValue (0 ) == 1 ) {
1455
- return true ;
1456
- }
1453
+ public static function isCapable ($ _function , $ _forceRefresh = false ) {
1454
+ global $ JEEDOM_COMPATIBILIY_CONFIG ;
1455
+ if ($ _function == 'sudo ' ) {
1456
+ if (!$ _forceRefresh ) {
1457
+ $ cache = cache::byKey ('jeedom::isCapable::sudo ' );
1458
+ if ($ cache ->getValue (0 ) == 1 ) {
1459
+ return true ;
1457
1460
}
1458
- $ result = (shell_exec ('sudo -l > /dev/null 2>&1; echo $? ' ) == 0 ) ? true : false ;
1459
- cache::set ('jeedom::isCapable::sudo ' , $ result ,3600 *24 );
1460
- return $ result ;
1461
- }
1462
- $ hardware = self ::getHardwareName ();
1463
- if (!isset ($ JEEDOM_COMPATIBILIY_CONFIG [$ hardware ])) {
1464
- return false ;
1465
- }
1466
- if (in_array ($ _function , $ JEEDOM_COMPATIBILIY_CONFIG [$ hardware ])) {
1467
- return true ;
1468
1461
}
1462
+ $ result = (shell_exec ('sudo -l > /dev/null 2>&1; echo $? ' ) == 0 ) ? true : false ;
1463
+ cache::set ('jeedom::isCapable::sudo ' , $ result ,3600 *24 );
1464
+ return $ result ;
1465
+ }
1466
+ $ hardware = self ::getHardwareName ();
1467
+ if (!isset ($ JEEDOM_COMPATIBILIY_CONFIG [$ hardware ])) {
1469
1468
return false ;
1470
1469
}
1470
+ if (in_array ($ _function , $ JEEDOM_COMPATIBILIY_CONFIG [$ hardware ])) {
1471
+ return true ;
1472
+ }
1473
+ return false ;
1474
+ }
1471
1475
1472
- /* * ******************Benchmark*************************** */
1473
-
1474
- public static function benchmark () {
1475
- $ return = array ();
1476
+ /* * ******************Benchmark*************************** */
1476
1477
1477
- $ param = array ('cache_write ' => 5000 , 'cache_read ' => 5000 , 'database_write_delete ' => 1000 , 'database_update ' => 1000 , 'database_replace ' => 1000 , 'database_read ' => 50000 , 'subprocess ' => 200 );
1478
+ public static function benchmark () {
1479
+ $ return = array ();
1478
1480
1479
- $ starttime = getmicrotime ();
1480
- for ($ i = 0 ; $ i < $ param ['cache_write ' ]; $ i ++) {
1481
- cache::set ('jeedom_benchmark ' , $ i );
1482
- }
1483
- $ return ['cache_write_ ' . $ param ['cache_write ' ]] = getmicrotime () - $ starttime ;
1481
+ $ param = array ('cache_write ' => 5000 , 'cache_read ' => 5000 , 'database_write_delete ' => 1000 , 'database_update ' => 1000 , 'database_replace ' => 1000 , 'database_read ' => 50000 , 'subprocess ' => 200 );
1484
1482
1485
- $ starttime = getmicrotime ();
1486
- for ($ i = 0 ; $ i < $ param ['cache_read ' ]; $ i ++) {
1487
- $ cache = cache::byKey ('jeedom_benchmark ' );
1488
- $ cache ->getValue ();
1489
- }
1490
- $ return ['cache_read_ ' . $ param ['cache_read ' ]] = getmicrotime () - $ starttime ;
1483
+ $ starttime = getmicrotime ();
1484
+ for ($ i = 0 ; $ i < $ param ['cache_write ' ]; $ i ++) {
1485
+ cache::set ('jeedom_benchmark ' , $ i );
1486
+ }
1487
+ $ return ['cache_write_ ' . $ param ['cache_write ' ]] = getmicrotime () - $ starttime ;
1491
1488
1492
- $ starttime = getmicrotime ();
1493
- for ($ i = 0 ; $ i < $ param ['database_write_delete ' ]; $ i ++) {
1494
- $ sql = 'DELETE FROM config
1495
- WHERE `key`="jeedom_benchmark"
1496
- AND plugin="core" ' ;
1497
- try {
1498
- DB ::Prepare ($ sql , array (), DB ::FETCH_TYPE_ROW );
1499
- } catch (Exception $ e ) {
1489
+ $ starttime = getmicrotime ();
1490
+ for ($ i = 0 ; $ i < $ param ['cache_read ' ]; $ i ++) {
1491
+ $ cache = cache::byKey ('jeedom_benchmark ' );
1492
+ $ cache ->getValue ();
1493
+ }
1494
+ $ return ['cache_read_ ' . $ param ['cache_read ' ]] = getmicrotime () - $ starttime ;
1500
1495
1501
- }
1502
- $ sql = 'INSERT INTO config
1503
- SET `key`="jeedom_benchmark",plugin="core",`value`=" ' . $ i . '" ' ;
1504
- try {
1505
- DB ::Prepare ($ sql , array (), DB ::FETCH_TYPE_ROW );
1506
- } catch (Exception $ e ) {
1496
+ $ starttime = getmicrotime ();
1497
+ for ($ i = 0 ; $ i < $ param ['database_write_delete ' ]; $ i ++) {
1498
+ $ sql = 'DELETE FROM config
1499
+ WHERE `key`="jeedom_benchmark"
1500
+ AND plugin="core" ' ;
1501
+ try {
1502
+ DB ::Prepare ($ sql , array (), DB ::FETCH_TYPE_ROW );
1503
+ } catch (Exception $ e ) {
1507
1504
1508
- }
1509
1505
}
1510
- $ return ['database_write_delete_ ' . $ param ['database_write_delete ' ]] = getmicrotime () - $ starttime ;
1511
-
1512
1506
$ sql = 'INSERT INTO config
1513
- SET `key`="jeedom_benchmark",plugin="core",`value`="0 " ' ;
1507
+ SET `key`="jeedom_benchmark",plugin="core",`value`=" ' . $ i . ' " ' ;
1514
1508
try {
1515
1509
DB ::Prepare ($ sql , array (), DB ::FETCH_TYPE_ROW );
1516
1510
} catch (Exception $ e ) {
1517
1511
1518
1512
}
1519
- $ starttime = getmicrotime ();
1520
- for ($ i = 0 ; $ i < $ param ['database_update ' ]; $ i ++) {
1521
- $ sql = 'UPDATE config
1522
- SET `value`=:value
1523
- WHERE `key`="jeedom_benchmark"
1524
- AND plugin="core" ' ;
1525
- try {
1526
- DB ::Prepare ($ sql , array ('value ' => $ i ), DB ::FETCH_TYPE_ROW );
1527
- } catch (Exception $ e ) {
1513
+ }
1514
+ $ return ['database_write_delete_ ' . $ param ['database_write_delete ' ]] = getmicrotime () - $ starttime ;
1528
1515
1529
- }
1530
- }
1531
- $ return ['database_update_ ' . $ param ['database_update ' ]] = getmicrotime () - $ starttime ;
1516
+ $ sql = 'INSERT INTO config
1517
+ SET `key`="jeedom_benchmark",plugin="core",`value`="0" ' ;
1518
+ try {
1519
+ DB ::Prepare ($ sql , array (), DB ::FETCH_TYPE_ROW );
1520
+ } catch (Exception $ e ) {
1532
1521
1533
- $ starttime = getmicrotime ();
1534
- for ($ i = 0 ; $ i < $ param ['database_replace ' ]; $ i ++) {
1535
- config::save ('jeedom_benchmark ' , $ i );
1536
- }
1537
- $ return ['database_replace_ ' . $ param ['database_replace ' ]] = getmicrotime () - $ starttime ;
1522
+ }
1523
+ $ starttime = getmicrotime ();
1524
+ for ($ i = 0 ; $ i < $ param ['database_update ' ]; $ i ++) {
1525
+ $ sql = 'UPDATE config
1526
+ SET `value`=:value
1527
+ WHERE `key`="jeedom_benchmark"
1528
+ AND plugin="core" ' ;
1529
+ try {
1530
+ DB ::Prepare ($ sql , array ('value ' => $ i ), DB ::FETCH_TYPE_ROW );
1531
+ } catch (Exception $ e ) {
1538
1532
1539
- $ starttime = getmicrotime ();
1540
- for ($ i = 0 ; $ i < $ param ['database_read ' ]; $ i ++) {
1541
- config::byKey ('jeedom_benchmark ' );
1542
1533
}
1543
- $ return ['database_read_ ' . $ param ['database_read ' ]] = getmicrotime () - $ starttime ;
1534
+ }
1535
+ $ return ['database_update_ ' . $ param ['database_update ' ]] = getmicrotime () - $ starttime ;
1544
1536
1545
- $ starttime = getmicrotime ();
1546
- for ($ i = 0 ; $ i < $ param ['subprocess ' ]; $ i ++) {
1547
- shell_exec ( ' echo ' . $ i );
1548
- }
1549
- $ return ['subprocess_ ' . $ param ['subprocess ' ]] = getmicrotime () - $ starttime ;
1537
+ $ starttime = getmicrotime ();
1538
+ for ($ i = 0 ; $ i < $ param ['database_replace ' ]; $ i ++) {
1539
+ config:: save ( ' jeedom_benchmark ' , $ i );
1540
+ }
1541
+ $ return ['database_replace_ ' . $ param ['database_replace ' ]] = getmicrotime () - $ starttime ;
1550
1542
1551
- $ total = 0 ;
1552
- foreach ($ return as $ value ) {
1553
- $ total += $ value ;
1554
- }
1555
- $ return ['total ' ] = $ total ;
1556
- return $ return ;
1543
+ $ starttime = getmicrotime ();
1544
+ for ($ i = 0 ; $ i < $ param ['database_read ' ]; $ i ++) {
1545
+ config::byKey ('jeedom_benchmark ' );
1557
1546
}
1547
+ $ return ['database_read_ ' . $ param ['database_read ' ]] = getmicrotime () - $ starttime ;
1548
+
1549
+ $ starttime = getmicrotime ();
1550
+ for ($ i = 0 ; $ i < $ param ['subprocess ' ]; $ i ++) {
1551
+ shell_exec ('echo ' . $ i );
1552
+ }
1553
+ $ return ['subprocess_ ' . $ param ['subprocess ' ]] = getmicrotime () - $ starttime ;
1554
+
1555
+ $ total = 0 ;
1556
+ foreach ($ return as $ value ) {
1557
+ $ total += $ value ;
1558
+ }
1559
+ $ return ['total ' ] = $ total ;
1560
+ return $ return ;
1558
1561
}
1562
+ }
0 commit comments