Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed postflight error in homebrew modules #991

Merged
merged 4 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 125 additions & 126 deletions app/modules/homebrew/homebrew_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,138 +69,137 @@ function __construct($serial='')
function process($json)
{
// Check if data was uploaded
if ( ! $json ){
throw new Exception("Error Processing Request: No JSON file found", 1);
}

// Delete previous set
$this->deleteWhere('serial_number=?', $this->serial_number);
if ( $json ){

// Delete previous set
$this->deleteWhere('serial_number=?', $this->serial_number);

// Process json into object thingy
$brews = json_decode($json, true);

$booleans = array('built_as_bottle','installed_as_dependency','installed_on_request','poured_from_bottle','keg_only','outdated','pinned','versions_bottle','versions_head');

$nestedarrays = array('versions','requirements','options','installed');

foreach ($brews as $singlebrew){

// Traverse the brew
foreach ($singlebrew as $key => $field) {

// Format booleans before processing
if (in_array($key, $booleans) && $field == "true") {
// Send a 1 to the db
$this->$key = '1';
} else if (in_array($key, $booleans)) {
// Send a 0 to the db
$this->$key = '0';
} else if (! empty($field) && ! is_array($field)) {
// If key is not empty, save it to the object
$this->$key = $field;
} else if (is_array($field) && ! in_array($key, $nestedarrays) && ! empty($field) && $key != "bottle"){
// If is an array and not a nested array, is not empty, and is not the bottle array, condense it to a string and save it
$this->$key = implode(", ", $field);
} else if ($key == "requirements" && ! empty($field)){
// Fill out the requirements values from the requirements array
$requirements = "";
foreach ($field as $requirement){
$requirements .= $requirement["name"].", ";
}
$this->requirements = trim($requirements, ", ");
} else if ($key == "versions" && ! empty($field)){
// Fill out the versions_ values from the versions array
$this->versions_stable = $field["stable"];
// versions_devel is a 0/1 for false/true
if ($field["devel"] != ""){
$this->versions_devel = '1';
} else{
$this->versions_devel = '0';
}
// versions_bottle is a 0/1 for false/true
if ($field["head"] == "bottle"){
$this->versions_bottle = '1';
} else{
$this->versions_bottle = '0';
}
// versions_head is a 0/1 for false/true
if ($field["head"] == "HEAD"){
$this->versions_head = '1';
} else{
$this->versions_head = '0';
}
} else if ($key == "installed" && ! empty($field)){
// installed_versions
$installed_versions = "";
foreach ($field as $installed_version){
$installed_versions .= $installed_version["version"].", ";
}
$this->installed_versions = trim($installed_versions, ", ");

$newestinstall = array_pop($field);

// check if options array is not blank, then fill from installed
if (! empty($newestinstall["used_options"])){
// Process json into object thingy
$brews = json_decode($json, true);

$booleans = array('built_as_bottle','installed_as_dependency','installed_on_request','poured_from_bottle','keg_only','outdated','pinned','versions_bottle','versions_head');

$nestedarrays = array('versions','requirements','options','installed');

foreach ($brews as $singlebrew){

// Traverse the brew
foreach ($singlebrew as $key => $field) {

// Format booleans before processing
if (in_array($key, $booleans) && $field == "true") {
// Send a 1 to the db
$this->$key = '1';
} else if (in_array($key, $booleans)) {
// Send a 0 to the db
$this->$key = '0';
} else if (! empty($field) && ! is_array($field)) {
// If key is not empty, save it to the object
$this->$key = $field;
} else if (is_array($field) && ! in_array($key, $nestedarrays) && ! empty($field) && $key != "bottle"){
// If is an array and not a nested array, is not empty, and is not the bottle array, condense it to a string and save it
$this->used_options = implode(", ", $newestinstall["used_options"]);
} else {
$this->used_options = "";
}
// built_as_bottle is a 0/1 for false/true
if ($newestinstall["built_as_bottle"] == "true"){
$this->built_as_bottle = '1';
} else{
$this->built_as_bottle = '0';
}
// installed_as_dependency is a 0/1 for false/true
if ($newestinstall["installed_as_dependency"] == "true"){
$this->installed_as_dependency = '1';
} else{
$this->installed_as_dependency = '0';
}
// installed_on_request is a 0/1 for false/true
if ($newestinstall["installed_on_request"] == "true"){
$this->installed_on_request = '1';
} else{
$this->installed_on_request = '0';
}
// poured_from_bottle is a 0/1 for false/true
if ($newestinstall["poured_from_bottle"] == "true"){
$this->poured_from_bottle = '1';
} else{
$this->poured_from_bottle = '0';
}
// runtime_dependencies
if (array_key_exists("runtime_dependencies", $newestinstall)) {
if ($newestinstall["runtime_dependencies"] != null){
$this->runtime_dependencies = implode(", ", array_column($newestinstall["runtime_dependencies"], 'full_name'));
$this->$key = implode(", ", $field);
} else if ($key == "requirements" && ! empty($field)){
// Fill out the requirements values from the requirements array
$requirements = "";
foreach ($field as $requirement){
$requirements .= $requirement["name"].", ";
}
$this->requirements = trim($requirements, ", ");
} else if ($key == "versions" && ! empty($field)){
// Fill out the versions_ values from the versions array
$this->versions_stable = $field["stable"];
// versions_devel is a 0/1 for false/true
if ($field["devel"] != ""){
$this->versions_devel = '1';
} else{
$this->versions_devel = '0';
}
// versions_bottle is a 0/1 for false/true
if ($field["head"] == "bottle"){
$this->versions_bottle = '1';
} else{
$this->versions_bottle = '0';
}
// versions_head is a 0/1 for false/true
if ($field["head"] == "HEAD"){
$this->versions_head = '1';
} else{
$this->versions_head = '0';
}
} else if ($key == "installed" && ! empty($field)){
// installed_versions
$installed_versions = "";
foreach ($field as $installed_version){
$installed_versions .= $installed_version["version"].", ";
}
$this->installed_versions = trim($installed_versions, ", ");

$newestinstall = array_pop($field);

// check if options array is not blank, then fill from installed
if (! empty($newestinstall["used_options"])){
// If is an array and not a nested array, is not empty, and is not the bottle array, condense it to a string and save it
$this->used_options = implode(", ", $newestinstall["used_options"]);
} else {
$this->used_options = "";
}
// built_as_bottle is a 0/1 for false/true
if ($newestinstall["built_as_bottle"] == "true"){
$this->built_as_bottle = '1';
} else{
$this->built_as_bottle = '0';
}
// installed_as_dependency is a 0/1 for false/true
if ($newestinstall["installed_as_dependency"] == "true"){
$this->installed_as_dependency = '1';
} else{
$this->installed_as_dependency = '0';
}
// installed_on_request is a 0/1 for false/true
if ($newestinstall["installed_on_request"] == "true"){
$this->installed_on_request = '1';
} else{
$this->installed_on_request = '0';
}
// poured_from_bottle is a 0/1 for false/true
if ($newestinstall["poured_from_bottle"] == "true"){
$this->poured_from_bottle = '1';
} else{
$this->poured_from_bottle = '0';
}
// runtime_dependencies
if (array_key_exists("runtime_dependencies", $newestinstall)) {
if ($newestinstall["runtime_dependencies"] != null){
$this->runtime_dependencies = implode(", ", array_column($newestinstall["runtime_dependencies"], 'full_name'));
} else {
$this->runtime_dependencies = "";
}
} else {
$this->runtime_dependencies = "";
$this->runtime_dependencies = "";
}
} else {
$this->runtime_dependencies = "";

} else if ($key == "options" && ! empty($field)){
// options
$options = "";
foreach ($field as $option){
$options .= $option["option"]." (".$option["description"]."), ";
}
$this->options = trim($options, ", ");


} else if ($field == "0" && ! is_array($field)){
// Set the value to 0 if it's 0
$this->$key = $field;
} else {
// Else, null the value
$this->$key = '';
}

} else if ($key == "options" && ! empty($field)){
// options
$options = "";
foreach ($field as $option){
$options .= $option["option"]." (".$option["description"]."), ";
}
$this->options = trim($options, ", ");


} else if ($field == "0" && ! is_array($field)){
// Set the value to 0 if it's 0
$this->$key = $field;
} else {
// Else, null the value
$this->$key = '';
// Save the bottles
$this->id = '';
$this->save();
}
}
// Save the bottles
$this->id = '';
$this->save();
}
}
}
}
7 changes: 4 additions & 3 deletions app/modules/homebrew/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ if [ $? = 0 ]; then
# Make executable
chmod a+x "${MUNKIPATH}preflight.d/homebrew.sh"

# Touch the cache file to prevent errors
mkdir -p "${MUNKIPATH}preflight.d/cache"
touch "${MUNKIPATH}preflight.d/cache/homebrew.json"

# Set preference to include this file in the preflight check
setreportpref "homebrew" "${CACHEPATH}homebrew.json"

# Touch the cache file to prevent errors
touch "${MUNKIPATH}preflight.d/cache/${MODULE_CACHE_FILE}"

else
echo "Failed to download all required components!"
rm -f "${MUNKIPATH}preflight.d/homebrew.sh"
Expand Down
103 changes: 51 additions & 52 deletions app/modules/homebrew_info/homebrew_info_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,61 +86,60 @@ function __construct($serial='')
function process($json)
{
// Check if data was uploaded
if ( ! $json ){
throw new Exception("Error Processing Request: No JSON file found", 1);
}
if ( $json ){

// Process json into object thingy
$brewinfo = json_decode($json, true);
// Translate brew info strings to db fields
$translate = array(
'CLT' => 'command_line_tools',
'CPU' => 'cpu',
'Clang' => 'clang',
'Core tap HEAD' => 'core_tap_head',
'Core tap ORIGIN' => 'core_tap_origin',
'Core tap last commit' => 'core_tap_last_commit',
'Git' => 'git',
'HEAD' => 'head',
'HOMEBREW_BOTTLE_DOMAIN' => 'homebrew_bottle_domain',
'HOMEBREW_CELLAR' => 'homebrew_cellar',
'HOMEBREW_PREFIX' => 'homebrew_prefix',
'HOMEBREW_REPOSITORY' => 'homebrew_repository',
'HOMEBREW_VERSION' => 'homebrew_version',
'Homebrew Ruby' => 'homebrew_ruby',
'Java' => 'java',
'Last commit' => 'last_commit',
'ORIGIN' => 'origin',
'Perl' => 'perl',
'Python' => 'python',
'Ruby' => 'ruby',
'X11' => 'x11',
'Xcode' => 'xcode',
'HOMEBREW_GIT_CONFIG_FILE' => 'homebrew_git_config_file',
'HOMEBREW_NO_ANALYTICS_THIS_RUN' => 'homebrew_noanalytics_this_run',
'Curl' => 'curl',
'macOS' => 'macos'
);
// Traverse the brew info with translations
foreach ($translate as $search => $field) {
// Process json into object thingy
$brewinfo = json_decode($json, true);

// Translate brew info strings to db fields
$translate = array(
'CLT' => 'command_line_tools',
'CPU' => 'cpu',
'Clang' => 'clang',
'Core tap HEAD' => 'core_tap_head',
'Core tap ORIGIN' => 'core_tap_origin',
'Core tap last commit' => 'core_tap_last_commit',
'Git' => 'git',
'HEAD' => 'head',
'HOMEBREW_BOTTLE_DOMAIN' => 'homebrew_bottle_domain',
'HOMEBREW_CELLAR' => 'homebrew_cellar',
'HOMEBREW_PREFIX' => 'homebrew_prefix',
'HOMEBREW_REPOSITORY' => 'homebrew_repository',
'HOMEBREW_VERSION' => 'homebrew_version',
'Homebrew Ruby' => 'homebrew_ruby',
'Java' => 'java',
'Last commit' => 'last_commit',
'ORIGIN' => 'origin',
'Perl' => 'perl',
'Python' => 'python',
'Ruby' => 'ruby',
'X11' => 'x11',
'Xcode' => 'xcode',
'HOMEBREW_GIT_CONFIG_FILE' => 'homebrew_git_config_file',
'HOMEBREW_NO_ANALYTICS_THIS_RUN' => 'homebrew_noanalytics_this_run',
'Curl' => 'curl',
'macOS' => 'macos'
);

// Traverse the brew info with translations
foreach ($translate as $search => $field) {

if (! array_key_exists($search, $brewinfo[0])){
// Skip keys that may not exist and null the value
$this->$field = '';
} else if (! empty($brewinfo[0][$search])) {
// If key is not empty, save it to the object
if (! array_key_exists($search, $brewinfo[0])){
// Skip keys that may not exist and null the value
$this->$field = '';
} else if (! empty($brewinfo[0][$search])) {
// If key is not empty, save it to the object
$this->$field = $brewinfo[0][$search];
} else if ($brewinfo[0][$search] == "0"){
// Set the value to 0 if it's 0
$this->$field = $brewinfo[0][$search];
} else if ($brewinfo[0][$search] == "0"){
// Set the value to 0 if it's 0
$this->$field = $brewinfo[0][$search];
} else {
// Else, null the value
$this->$field = '';
} else {
// Else, null the value
$this->$field = '';
}
}
// Save the info
$this->save();
}
// Save the info
$this->save();
}
}
}
Loading