<commit_before><?php

//
// Author: CYOSP
// Version: 1.2.0
// Dependencies:
//  - php_curl (sudo apt-get install php5-curl)
//
// 2017-03-29 V 1.2.0
//  - Manage crontab condition
// 2016-12-27 V 1.1.0
//  - Manage new crontab disabled state
// 2016-10-09 V 1.0.0
//  - First release
//

// Require CronExpression
// Order is important
require_once '../../../src/Cron/FieldInterface.php';
require_once '../../../src/Cron/AbstractField.php';
require_once '../../../src/Cron/CronExpression.php';
require_once '../../../src/Cron/DayOfMonthField.php';
require_once '../../../src/Cron/DayOfWeekField.php';
require_once '../../../src/Cron/FieldFactory.php';
require_once '../../../src/Cron/HoursField.php';
require_once '../../../src/Cron/MinutesField.php';
require_once '../../../src/Cron/MonthField.php';
require_once '../../../src/Cron/YearField.php';

// Get and parse JSON configuration file
$data = json_decode( file_get_contents( "../../../data/config.json" ) , true );
// Get WiringPi pin number
$emitterWiringPiNumber=$data['emitterWiringPiNumber'];

echo "emitterWiringPiNumber: ".$emitterWiringPiNumber."<br/>";

//
// For each switch
//
foreach( $data['switchesList'] as $i => $switch )
{
	// Check there is a crontab entry
	if( array_key_exists( 'crontab' , $switch ) )
	{
		//
		// For each crontab entry
		//
		foreach( $switch['crontab'] as $j => $cronEntry )
		{
			echo $switch['label'].' - rcId='.$switch['rcId'].', channel='.$switch['channel'].' : '.$cronEntry['cron'].' '. $cronEntry['state'].'<br/>';

			// There is a state to manage
			if( $cronEntry['state'] != "disabled" )
			{
				// Setup CronExpression
				$cron = Cron\CronExpression::factory( $cronEntry['cron'] );

				// Cron state must be applied
				if( $cron->isDue() )
				{
					// By default crontab condition is assuming true
					// It allows to execute crontab when there is no condition
					$cronCondition = true;

					// Check there is a crontab condition
					if( array_key_exists( 'condition' , $cronEntry ) && $cronEntry['condition'] != "" )
					{
						// Execute node.js script to verify crontab condition
						$output = shell_exec( "node crontab-condition.js " . $i . " " . $j ." 2>&1 >/dev/null; echo $?" );

						// Analyze execution to know crontab condition value
						if( strcmp( $output , "0\n" ) != 0 )	$cronCondition = false;
					}

					if( $cronCondition )
					{<commit_msg>Switch nodejs binary name from node to nodejs<commit_after><?php

//
// Author: CYOSP
// Version: 1.2.0
// Dependencies:
//  - php_curl (sudo apt-get install php5-curl)
//
// 2017-03-29 V 1.2.0
//  - Manage crontab condition
// 2016-12-27 V 1.1.0
//  - Manage new crontab disabled state
// 2016-10-09 V 1.0.0
//  - First release
//

// Require CronExpression
// Order is important
require_once '../../../src/Cron/FieldInterface.php';
require_once '../../../src/Cron/AbstractField.php';
require_once '../../../src/Cron/CronExpression.php';
require_once '../../../src/Cron/DayOfMonthField.php';
require_once '../../../src/Cron/DayOfWeekField.php';
require_once '../../../src/Cron/FieldFactory.php';
require_once '../../../src/Cron/HoursField.php';
require_once '../../../src/Cron/MinutesField.php';
require_once '../../../src/Cron/MonthField.php';
require_once '../../../src/Cron/YearField.php';

// Get and parse JSON configuration file
$data = json_decode( file_get_contents( "../../../data/config.json" ) , true );
// Get WiringPi pin number
$emitterWiringPiNumber=$data['emitterWiringPiNumber'];

echo "emitterWiringPiNumber: ".$emitterWiringPiNumber."<br/>";

//
// For each switch
//
foreach( $data['switchesList'] as $i => $switch )
{
	// Check there is a crontab entry
	if( array_key_exists( 'crontab' , $switch ) )
	{
		//
		// For each crontab entry
		//
		foreach( $switch['crontab'] as $j => $cronEntry )
		{
			echo $switch['label'].' - rcId='.$switch['rcId'].', channel='.$switch['channel'].' : '.$cronEntry['cron'].' '. $cronEntry['state'].'<br/>';

			// There is a state to manage
			if( $cronEntry['state'] != "disabled" )
			{
				// Setup CronExpression
				$cron = Cron\CronExpression::factory( $cronEntry['cron'] );

				// Cron state must be applied
				if( $cron->isDue() )
				{
					// By default crontab condition is assuming true
					// It allows to execute crontab when there is no condition
					$cronCondition = true;

					// Check there is a crontab condition
					if( array_key_exists( 'condition' , $cronEntry ) && $cronEntry['condition'] != "" )
					{
						// Execute node.js script to verify crontab condition
						$output = shell_exec( "nodejs crontab-condition.js " . $i . " " . $j ." 2>&1 >/dev/null; echo $?" );

						// Analyze execution to know crontab condition value
						if( strcmp( $output , "0\n" ) != 0 )	$cronCondition = false;
					}

					if( $cronCondition )
					{
{'fraction_non_alphanumeric': 0.1970893970893971, 'fraction_numerical': 0.01704781704781705, 'mean_word_length': 2.7121913580246915, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2650215', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1648, 'n_words': 387}