Issue #2915011: Move farm_log_movement to farm_movement

This commit is contained in:
Michael Stenta 2017-10-10 17:55:24 -04:00
parent 01f95f3058
commit 7dc626a450
35 changed files with 135 additions and 112 deletions

View File

@ -626,6 +626,29 @@ function farm_update_7030(&$sandbox) {
_farm_update_enable_modules(array('help')); _farm_update_enable_modules(array('help'));
} }
/**
* Rename farm_log_movement to farm_movement in the {system} table.
*/
function farm_update_7031(&$sandbox) {
// Drupal will autodetect farm_movement as a new module, and will think
// farm_log_movement is missing - so we need to do some tricky
// bait-and-switch to rename the module and ensure that it stays enabled.
// Load the {system} record for farm_log_movement, and make our modifications.
$record = db_query("SELECT * FROM {system} WHERE name = 'farm_log_movement' AND type = 'module'")->fetch();
$record->name = str_replace('farm_log_movement', 'farm_movement', $record->name);
$record->filename = str_replace('farm_log/farm_log_movement', 'farm_movement', $record->filename);
$record->status = 1;
// Delete any farm_log_movement and farm_movement records.
db_query("DELETE FROM {system} WHERE name = 'farm_log_movement' AND type = 'module'");
db_query("DELETE FROM {system} WHERE name = 'farm_movement' AND type = 'module'");
// Re-save the original record.
drupal_write_record('system', $record);
}
/** /**
* Update helper function: enable modules. * Update helper function: enable modules.
*/ */

View File

@ -13,8 +13,8 @@ dependencies[] = farm_area
dependencies[] = farm_asset dependencies[] = farm_asset
dependencies[] = farm_asset_children dependencies[] = farm_asset_children
dependencies[] = farm_fields dependencies[] = farm_fields
dependencies[] = farm_log_movement
dependencies[] = farm_map dependencies[] = farm_map
dependencies[] = farm_movement
dependencies[] = farm_quantity dependencies[] = farm_quantity
dependencies[] = farm_season dependencies[] = farm_season
dependencies[] = features dependencies[] = features

View File

@ -22,8 +22,8 @@ function farm_crop_update_dependencies() {
$dependencies['farm_crop'][7002] = array('farm' => 7019); $dependencies['farm_crop'][7002] = array('farm' => 7019);
// Update 7003 (add movement field to seedings and transplantings) depends on // Update 7003 (add movement field to seedings and transplantings) depends on
// farm_log_movement_update_7000(). // farm_movement_update_7000().
$dependencies['farm_crop'][7003] = array('farm_log_movement' => 7000); $dependencies['farm_crop'][7003] = array('farm_movement' => 7000);
return $dependencies; return $dependencies;
} }

View File

@ -119,7 +119,7 @@ function farm_crop_planting_plan_submit(array $form, array &$form_state) {
// If the location is available, load areas. // If the location is available, load areas.
$areas = array(); $areas = array();
if (!empty($form_state['values'][$type . '_location'])) { if (!empty($form_state['values'][$type . '_location'])) {
$areas = farm_log_movement_parse_areas($form_state['values'][$type . '_location']); $areas = farm_movement_parse_areas($form_state['values'][$type . '_location']);
} }
// Mark the log as done or not done. // Mark the log as done or not done.
@ -129,7 +129,7 @@ function farm_crop_planting_plan_submit(array $form, array &$form_state) {
} }
// Create a log. // Create a log.
farm_log_movement_create($asset, $areas, $timestamp, 'farm_' . $type, $done); farm_movement_create($asset, $areas, $timestamp, 'farm_' . $type, $done);
} }
} }

View File

@ -1222,7 +1222,7 @@ function farm_crop_views_default_views() {
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0; $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10'; $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array( $handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
'action::farm_log_movement_asset_move_action' => array( 'action::farm_movement_asset_move_action' => array(
'selected' => 1, 'selected' => 1,
'skip_confirmation' => 1, 'skip_confirmation' => 1,
'override_label' => 0, 'override_label' => 0,

View File

@ -10,7 +10,7 @@ dependencies[] = entityreference
dependencies[] = entityreference_view_widget dependencies[] = entityreference_view_widget
dependencies[] = farm_asset dependencies[] = farm_asset
dependencies[] = farm_fields dependencies[] = farm_fields
dependencies[] = farm_log_movement dependencies[] = farm_movement
dependencies[] = features dependencies[] = features
dependencies[] = field_collection dependencies[] = field_collection
dependencies[] = field_group dependencies[] = field_group

View File

@ -10,8 +10,8 @@
function farm_equipment_update_dependencies() { function farm_equipment_update_dependencies() {
// Update 7002 (add new movement field to maintenance logs) depends on // Update 7002 (add new movement field to maintenance logs) depends on
// farm_log_movement_update_7000(). // farm_movement_update_7000().
$dependencies['farm_equipment'][7002] = array('farm_log_movement' => 7000); $dependencies['farm_equipment'][7002] = array('farm_movement' => 7000);
return $dependencies; return $dependencies;
} }

View File

@ -136,7 +136,7 @@ function farm_equipment_views_default_views() {
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0; $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10'; $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array( $handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
'action::farm_log_movement_asset_move_action' => array( 'action::farm_movement_asset_move_action' => array(
'selected' => 1, 'selected' => 1,
'skip_confirmation' => 1, 'skip_confirmation' => 1,
'override_label' => 0, 'override_label' => 0,

View File

@ -11,8 +11,8 @@ dependencies[] = entityreference_view_widget
dependencies[] = farm_asset dependencies[] = farm_asset
dependencies[] = farm_asset_children dependencies[] = farm_asset_children
dependencies[] = farm_fields dependencies[] = farm_fields
dependencies[] = farm_log_movement
dependencies[] = farm_map dependencies[] = farm_map
dependencies[] = farm_movement
dependencies[] = features dependencies[] = features
dependencies[] = field_collection dependencies[] = field_collection
dependencies[] = field_group dependencies[] = field_group

View File

@ -14,8 +14,8 @@ function farm_livestock_update_dependencies() {
$dependencies['farm_livestock'][7001] = array('farm' => 7019); $dependencies['farm_livestock'][7001] = array('farm' => 7019);
// Update 7003 (add movement field to medical logs) depends on // Update 7003 (add movement field to medical logs) depends on
// farm_log_movement_update_7000(). // farm_movement_update_7000().
$dependencies['farm_livestock'][7003] = array('farm_log_movement' => 7000); $dependencies['farm_livestock'][7003] = array('farm_movement' => 7000);
return $dependencies; return $dependencies;
} }

View File

@ -427,7 +427,7 @@ function farm_livestock_views_default_views() {
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0; $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10'; $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array( $handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
'action::farm_log_movement_asset_move_action' => array( 'action::farm_movement_asset_move_action' => array(
'selected' => 1, 'selected' => 1,
'skip_confirmation' => 1, 'skip_confirmation' => 1,
'override_label' => 0, 'override_label' => 0,

View File

@ -30,8 +30,8 @@ function farm_log_update_dependencies() {
$dependencies['farm_log'][7001] = array('log' => 7002); $dependencies['farm_log'][7001] = array('log' => 7002);
// Update 7006 (Add movement field to activities, harvests, inputs, and // Update 7006 (Add movement field to activities, harvests, inputs, and
// observations.) depends on farm_log_movement_update_7000(). // observations.) depends on farm_movement_update_7000().
$dependencies['farm_log'][7006] = array('farm_log_movement' => 7000); $dependencies['farm_log'][7006] = array('farm_movement' => 7000);
return $dependencies; return $dependencies;
} }
@ -268,8 +268,8 @@ function farm_log_update_7004(&$sandbox) {
'farm_log_activity', 'farm_log_activity',
'farm_log_harvest', 'farm_log_harvest',
'farm_log_input', 'farm_log_input',
'farm_log_movement',
'farm_log_observation', 'farm_log_observation',
'farm_movement',
); );
foreach ($modules as $module) { foreach ($modules as $module) {
if (!module_exists($module)) { if (!module_exists($module)) {

View File

@ -13,8 +13,8 @@ dependencies[] = entityreference_view_widget
dependencies[] = farm_area dependencies[] = farm_area
dependencies[] = farm_asset dependencies[] = farm_asset
dependencies[] = farm_fields dependencies[] = farm_fields
dependencies[] = farm_log_movement
dependencies[] = farm_map dependencies[] = farm_map
dependencies[] = farm_movement
dependencies[] = features dependencies[] = features
dependencies[] = field_collection dependencies[] = field_collection
dependencies[] = field_group dependencies[] = field_group

View File

@ -13,8 +13,8 @@ dependencies[] = entityreference_view_widget
dependencies[] = farm_area dependencies[] = farm_area
dependencies[] = farm_asset dependencies[] = farm_asset
dependencies[] = farm_fields dependencies[] = farm_fields
dependencies[] = farm_log_movement
dependencies[] = farm_map dependencies[] = farm_map
dependencies[] = farm_movement
dependencies[] = farm_quantity dependencies[] = farm_quantity
dependencies[] = features dependencies[] = features
dependencies[] = field_collection dependencies[] = field_collection

View File

@ -13,8 +13,8 @@ dependencies[] = entityreference_view_widget
dependencies[] = farm_area dependencies[] = farm_area
dependencies[] = farm_asset dependencies[] = farm_asset
dependencies[] = farm_fields dependencies[] = farm_fields
dependencies[] = farm_log_movement
dependencies[] = farm_map dependencies[] = farm_map
dependencies[] = farm_movement
dependencies[] = farm_quantity dependencies[] = farm_quantity
dependencies[] = features dependencies[] = features
dependencies[] = field_collection dependencies[] = field_collection

View File

@ -13,8 +13,8 @@ dependencies[] = entityreference_view_widget
dependencies[] = farm_area dependencies[] = farm_area
dependencies[] = farm_asset dependencies[] = farm_asset
dependencies[] = farm_fields dependencies[] = farm_fields
dependencies[] = farm_log_movement
dependencies[] = farm_map dependencies[] = farm_map
dependencies[] = farm_movement
dependencies[] = farm_quantity dependencies[] = farm_quantity
dependencies[] = features dependencies[] = features
dependencies[] = field_collection dependencies[] = field_collection

View File

@ -1,13 +1,13 @@
<?php <?php
/** /**
* @file * @file
* farm_log_movement.default_openlayers_components.inc * farm_movement.default_openlayers_components.inc
*/ */
/** /**
* Implements hook_default_openlayers_components(). * Implements hook_default_openlayers_components().
*/ */
function farm_log_movement_default_openlayers_components() { function farm_movement_default_openlayers_components() {
$export = array(); $export = array();
// Get farm asset types. // Get farm asset types.

View File

@ -1,13 +1,13 @@
<?php <?php
/** /**
* @file * @file
* farm_log_movement.default_openlayers_layers.inc * farm_movement.default_openlayers_layers.inc
*/ */
/** /**
* Implements hook_default_openlayers_layers(). * Implements hook_default_openlayers_layers().
*/ */
function farm_log_movement_default_openlayers_layers() { function farm_movement_default_openlayers_layers() {
$export = array(); $export = array();
// Load all available asset types. // Load all available asset types.

View File

@ -1,13 +1,13 @@
<?php <?php
/** /**
* @file * @file
* farm_log_movement.default_openlayers_maps.inc * farm_movement.default_openlayers_maps.inc
*/ */
/** /**
* Implements hook_default_openlayers_maps(). * Implements hook_default_openlayers_maps().
*/ */
function farm_log_movement_default_openlayers_maps() { function farm_movement_default_openlayers_maps() {
$export = array(); $export = array();
// Get farm asset types. // Get farm asset types.

View File

@ -1,13 +1,13 @@
<?php <?php
/** /**
* @file * @file
* farm_log_movement.default_openlayers_sources.inc * farm_movement.default_openlayers_sources.inc
*/ */
/** /**
* Implements hook_default_openlayers_sources(). * Implements hook_default_openlayers_sources().
*/ */
function farm_log_movement_default_openlayers_sources() { function farm_movement_default_openlayers_sources() {
$export = array(); $export = array();
// Load all available farm asset types. // Load all available farm asset types.

View File

@ -1,13 +1,13 @@
<?php <?php
/** /**
* @file * @file
* farm_log_movement.features.field_base.inc * farm_movement.features.field_base.inc
*/ */
/** /**
* Implements hook_field_default_field_bases(). * Implements hook_field_default_field_bases().
*/ */
function farm_log_movement_field_default_field_bases() { function farm_movement_field_default_field_bases() {
$field_bases = array(); $field_bases = array();
// Exported field_base: 'field_farm_move_from'. // Exported field_base: 'field_farm_move_from'.

View File

@ -1,13 +1,13 @@
<?php <?php
/** /**
* @file * @file
* farm_log_movement.features.field_instance.inc * farm_movement.features.field_instance.inc
*/ */
/** /**
* Implements hook_field_default_field_instances(). * Implements hook_field_default_field_instances().
*/ */
function farm_log_movement_field_default_field_instances() { function farm_movement_field_default_field_instances() {
$field_instances = array(); $field_instances = array();
// Exported field_instance: // Exported field_instance:

View File

@ -1,13 +1,13 @@
<?php <?php
/** /**
* @file * @file
* farm_log_movement.features.inc * farm_movement.features.inc
*/ */
/** /**
* Implements hook_ctools_plugin_api(). * Implements hook_ctools_plugin_api().
*/ */
function farm_log_movement_ctools_plugin_api($module = NULL, $api = NULL) { function farm_movement_ctools_plugin_api($module = NULL, $api = NULL) {
if ($module == "field_group" && $api == "field_group") { if ($module == "field_group" && $api == "field_group") {
return array("version" => "1"); return array("version" => "1");
} }
@ -28,6 +28,6 @@ function farm_log_movement_ctools_plugin_api($module = NULL, $api = NULL) {
/** /**
* Implements hook_views_api(). * Implements hook_views_api().
*/ */
function farm_log_movement_views_api($module = NULL, $api = NULL) { function farm_movement_views_api($module = NULL, $api = NULL) {
return array("api" => "3.0"); return array("api" => "3.0");
} }

View File

@ -1,13 +1,13 @@
<?php <?php
/** /**
* @file * @file
* farm_log_movement.field_group.inc * farm_movement.field_group.inc
*/ */
/** /**
* Implements hook_field_group_info(). * Implements hook_field_group_info().
*/ */
function farm_log_movement_field_group_info() { function farm_movement_field_group_info() {
$field_groups = array(); $field_groups = array();
$field_group = new stdClass(); $field_group = new stdClass();

View File

@ -1,4 +1,4 @@
name = Farm Log: Movement name = Farm Movement
description = Provides movement field and related asset location code. description = Provides movement field and related asset location code.
core = 7.x core = 7.x
package = farmOS package = farmOS
@ -37,5 +37,5 @@ features[field_instance][] = field_collection_item-field_farm_movement-field_far
features[field_instance][] = field_collection_item-field_farm_movement-field_farm_move_to features[field_instance][] = field_collection_item-field_farm_movement-field_farm_move_to
features[views_view][] = farm_area_assets features[views_view][] = farm_area_assets
features[views_view][] = farm_asset_geojson features[views_view][] = farm_asset_geojson
features[views_view][] = farm_log_movement features[views_view][] = farm_movement_log
files[] = views/handlers/farm_log_movement_handler_relationship_location.inc files[] = views/handlers/farm_movement_handler_relationship_location.inc

View File

@ -1,16 +1,16 @@
<?php <?php
/** /**
* @file * @file
* Code for Farm Log: Movement installation/updates. * Code for farm movement installation/updates.
*/ */
/** /**
* Create new movement field collection. * Create new movement field collection.
*/ */
function farm_log_movement_update_7000(&$sandbox) { function farm_movement_update_7000(&$sandbox) {
// Revert this module's field_base and field_instance components // Revert this module's field_base and field_instance components
features_revert(array('farm_log_movement' => array('field_base', 'field_instance'))); features_revert(array('farm_movement' => array('field_base', 'field_instance')));
// Flush all caches. // Flush all caches.
drupal_flush_all_caches(); drupal_flush_all_caches();
@ -47,7 +47,7 @@ function farm_log_movement_update_7000(&$sandbox) {
/** /**
* Migrate movement data into new field_farm_movement field collections. * Migrate movement data into new field_farm_movement field collections.
*/ */
function farm_log_movement_update_7001(&$sandbox) { function farm_movement_update_7001(&$sandbox) {
// Process this in passes of 50 movements at a time. // Process this in passes of 50 movements at a time.
$sandbox['#finished'] = 0; $sandbox['#finished'] = 0;
@ -154,13 +154,13 @@ function farm_log_movement_update_7001(&$sandbox) {
/** /**
* Migrate movement logs to activity logs. * Migrate movement logs to activity logs.
*/ */
function farm_log_movement_update_7002(&$sandbox) { function farm_movement_update_7002(&$sandbox) {
// Search for fields that exist on movements, but not on activities, so we can // Search for fields that exist on movements, but not on activities, so we can
// move them to activities. This would only be the case if a user added their // move them to activities. This would only be the case if a user added their
// own fields, movements do not have any extra fields in default farmOS. // own fields, movements do not have any extra fields in default farmOS.
// (They used to, but the "move to" and "move from" moved to the new // (They used to, but the "move to" and "move from" moved to the new
// field_farm_movement field collection. See farm_log_movement_update_7001()). // field_farm_movement field collection. See farm_movement_update_7001()).
$log_types = array( $log_types = array(
'farm_movement', 'farm_movement',
'farm_activity', 'farm_activity',
@ -200,7 +200,7 @@ function farm_log_movement_update_7002(&$sandbox) {
/** /**
* Remove movement log type. * Remove movement log type.
*/ */
function farm_log_movement_update_7003(&$sandbox) { function farm_movement_update_7003(&$sandbox) {
// Delete the movement log type, if it exists. // Delete the movement log type, if it exists.
$log_type = log_type_load('farm_movement'); $log_type = log_type_load('farm_movement');

View File

@ -13,13 +13,13 @@
* @return string * @return string
* Returns rendered HTML. * Returns rendered HTML.
*/ */
function farm_log_movement_asset_location_markup($asset) { function farm_movement_asset_location_markup($asset) {
// Start an output string. // Start an output string.
$output = '<strong>' . t('Location') . ':</strong> '; $output = '<strong>' . t('Location') . ':</strong> ';
// Get the asset's location. // Get the asset's location.
$areas = farm_log_movement_asset_location($asset); $areas = farm_movement_asset_location($asset);
// If locations were found, add links to them. // If locations were found, add links to them.
if (!empty($areas)) { if (!empty($areas)) {
@ -38,7 +38,7 @@ function farm_log_movement_asset_location_markup($asset) {
} }
// Get the asset's most recent movement. // Get the asset's most recent movement.
$log = farm_log_movement_asset_latest_movement($asset); $log = farm_movement_asset_latest_movement($asset);
// Load the log's movement field, if it exists. // Load the log's movement field, if it exists.
if (!empty($log->field_farm_movement[LANGUAGE_NONE][0]['value'])) { if (!empty($log->field_farm_movement[LANGUAGE_NONE][0]['value'])) {
@ -62,13 +62,13 @@ function farm_log_movement_asset_location_markup($asset) {
/** /**
* Implements hook_form_FORM_ID_alter(). * Implements hook_form_FORM_ID_alter().
*/ */
function farm_log_movement_form_farm_asset_form_alter(&$form, &$form_state, $form_id) { function farm_movement_form_farm_asset_form_alter(&$form, &$form_state, $form_id) {
// Get the farm asset entity from the form. // Get the farm asset entity from the form.
$asset = $form['farm_asset']['#value']; $asset = $form['farm_asset']['#value'];
// Get the asset's current location. // Get the asset's current location.
$areas = farm_log_movement_asset_location($asset); $areas = farm_movement_asset_location($asset);
$area_names = array(); $area_names = array();
if (!empty($areas)) { if (!empty($areas)) {
foreach ($areas as $area) { foreach ($areas as $area) {
@ -100,13 +100,13 @@ function farm_log_movement_form_farm_asset_form_alter(&$form, &$form_state, $for
'#collapsed' => TRUE, '#collapsed' => TRUE,
'#weight' => 100, '#weight' => 100,
); );
$form['location']['farm_log_movement_asset_location'] = array( $form['location']['farm_movement_asset_location'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Current location'), '#title' => t('Current location'),
'#autocomplete_path' => 'taxonomy/autocomplete/field_farm_area', '#autocomplete_path' => 'taxonomy/autocomplete/field_farm_area',
'#default_value' => $location, '#default_value' => $location,
); );
$form['actions']['submit']['#submit'][] = 'farm_log_movement_asset_location_submit'; $form['actions']['submit']['#submit'][] = 'farm_movement_asset_location_submit';
$form['#group_children']['location'] = 'group_farm_general'; $form['#group_children']['location'] = 'group_farm_general';
} }
@ -118,15 +118,15 @@ function farm_log_movement_form_farm_asset_form_alter(&$form, &$form_state, $for
* @param array $form_state * @param array $form_state
* The form state array. * The form state array.
*/ */
function farm_log_movement_asset_location_submit(array $form, array &$form_state) { function farm_movement_asset_location_submit(array $form, array &$form_state) {
// Only proceed if farm_log_movement_asset_location has a value. // Only proceed if farm_movement_asset_location has a value.
if (empty($form_state['values']['farm_log_movement_asset_location'])) { if (empty($form_state['values']['farm_movement_asset_location'])) {
return; return;
} }
// Only proceed if the value is not the default value. // Only proceed if the value is not the default value.
if ($form_state['values']['farm_log_movement_asset_location'] == $form['location']['farm_log_movement_asset_location']['#default_value']) { if ($form_state['values']['farm_movement_asset_location'] == $form['location']['farm_movement_asset_location']['#default_value']) {
return; return;
} }
@ -139,10 +139,10 @@ function farm_log_movement_asset_location_submit(array $form, array &$form_state
$asset = $form_state['values']['farm_asset']; $asset = $form_state['values']['farm_asset'];
// Load the areas. // Load the areas.
$areas = farm_log_movement_parse_areas($form_state['values']['farm_log_movement_asset_location']); $areas = farm_movement_parse_areas($form_state['values']['farm_movement_asset_location']);
// Create an observation log to record the movement. // Create an observation log to record the movement.
farm_log_movement_create($asset, $areas, REQUEST_TIME); farm_movement_create($asset, $areas, REQUEST_TIME);
} }
/** /**
@ -154,7 +154,7 @@ function farm_log_movement_asset_location_submit(array $form, array &$form_state
* @return array * @return array
* Returns an array of loaded area entities. * Returns an array of loaded area entities.
*/ */
function farm_log_movement_parse_areas($area_names) { function farm_movement_parse_areas($area_names) {
// Start with an empty array. // Start with an empty array.
$areas = array(); $areas = array();
@ -207,11 +207,11 @@ function farm_log_movement_parse_areas($area_names) {
* @return array * @return array
* Returns an array of areas that the asset is in. * Returns an array of areas that the asset is in.
*/ */
function farm_log_movement_asset_location(FarmAsset $asset, $time = REQUEST_TIME, $done = TRUE) { function farm_movement_asset_location(FarmAsset $asset, $time = REQUEST_TIME, $done = TRUE) {
$areas = array(); $areas = array();
// Load the log using our helper function. // Load the log using our helper function.
$log = farm_log_movement_asset_latest_movement($asset, $time, $done); $log = farm_movement_asset_latest_movement($asset, $time, $done);
// If a movement field doesn't exist, bail. // If a movement field doesn't exist, bail.
if (empty($log->field_farm_movement[LANGUAGE_NONE][0]['value'])) { if (empty($log->field_farm_movement[LANGUAGE_NONE][0]['value'])) {
@ -249,7 +249,7 @@ function farm_log_movement_asset_location(FarmAsset $asset, $time = REQUEST_TIME
* @return Log|bool * @return Log|bool
* Returns a log entity. FALSE if something goes wrong. * Returns a log entity. FALSE if something goes wrong.
*/ */
function farm_log_movement_asset_latest_movement(FarmAsset $asset, $time = REQUEST_TIME, $done = TRUE) { function farm_movement_asset_latest_movement(FarmAsset $asset, $time = REQUEST_TIME, $done = TRUE) {
// If the asset doesn't have an ID (for instance if it is new and hasn't been // If the asset doesn't have an ID (for instance if it is new and hasn't been
// saved yet), bail. // saved yet), bail.
@ -258,7 +258,7 @@ function farm_log_movement_asset_latest_movement(FarmAsset $asset, $time = REQUE
} }
// Make a query for loading the latest movement log. // Make a query for loading the latest movement log.
$query = farm_log_movement_asset_movement_query($asset->id, $time, $done); $query = farm_movement_asset_movement_query($asset->id, $time, $done);
// Execute the query and gather the log id. // Execute the query and gather the log id.
$result = $query->execute(); $result = $query->execute();
@ -278,7 +278,7 @@ function farm_log_movement_asset_latest_movement(FarmAsset $asset, $time = REQUE
* The asset id to search for. This can either be a specific id, or a field * The asset id to search for. This can either be a specific id, or a field
* alias string from another query (ie: 'mytable.assetid'). For an example * alias string from another query (ie: 'mytable.assetid'). For an example
* of field alias string usage, see the Views field handler code in * of field alias string usage, see the Views field handler code in
* farm_log_movement_handler_relationship_location::query(). * farm_movement_handler_relationship_location::query().
* @param int $time * @param int $time
* Unix timestamp limiter. Only logs before this time will be included. * Unix timestamp limiter. Only logs before this time will be included.
* Defaults to the current time. Set to 0 to load the absolute last. * Defaults to the current time. Set to 0 to load the absolute last.
@ -292,11 +292,11 @@ function farm_log_movement_asset_latest_movement(FarmAsset $asset, $time = REQUE
* @return \SelectQuery * @return \SelectQuery
* Returns a SelectQuery object. * Returns a SelectQuery object.
*/ */
function farm_log_movement_asset_movement_query($asset_id, $time = REQUEST_TIME, $done = TRUE, $field = 'log_id') { function farm_movement_asset_movement_query($asset_id, $time = REQUEST_TIME, $done = TRUE, $field = 'log_id') {
/** /**
* This query is used as a subquery join in the Views handler * This query is used as a subquery join in the Views handler
* farm_log_movement_handler_relationship_location (via the * farm_movement_handler_relationship_location (via the
* views_join_subquery class). views_join_subquery does not support query * views_join_subquery class). views_join_subquery does not support query
* arguments, so we cannot use the query::condition() method, or any other * arguments, so we cannot use the query::condition() method, or any other
* instances where args() are passed in and replaced in the query. So it is * instances where args() are passed in and replaced in the query. So it is
@ -317,7 +317,7 @@ function farm_log_movement_asset_movement_query($asset_id, $time = REQUEST_TIME,
// Build a query to find an asset's latest log that defines a movement. // Build a query to find an asset's latest log that defines a movement.
// We use the "ss_" prefix throughout to indicate that this is generally going // We use the "ss_" prefix throughout to indicate that this is generally going
// to be used as a sub-select, and to avoid potential name conflicts when this // to be used as a sub-select, and to avoid potential name conflicts when this
// is used elsewhere (ie: farm_log_handler_relationship_location::query()). // is used elsewhere (ie: farm_movement_handler_relationship_location::query()).
$query = db_select('log', 'ss_log'); $query = db_select('log', 'ss_log');
// Join in asset references and filter to only include logs that reference the // Join in asset references and filter to only include logs that reference the
@ -365,9 +365,9 @@ function farm_log_movement_asset_movement_query($asset_id, $time = REQUEST_TIME,
/** /**
* Implements hook_action_info(). * Implements hook_action_info().
*/ */
function farm_log_movement_action_info() { function farm_movement_action_info() {
return array( return array(
'farm_log_movement_asset_move_action' => array( 'farm_movement_asset_move_action' => array(
'type' => 'farm_asset', 'type' => 'farm_asset',
'label' => t('Move'), 'label' => t('Move'),
'configurable' => TRUE, 'configurable' => TRUE,
@ -378,7 +378,7 @@ function farm_log_movement_action_info() {
} }
/** /**
* Configuration form for farm_log_movement_asset_move action. * Configuration form for farm_movement_asset_move action.
* *
* @param array $context * @param array $context
* The context passed into the action form function. * The context passed into the action form function.
@ -388,7 +388,7 @@ function farm_log_movement_action_info() {
* @return array * @return array
* Returns a form array. * Returns a form array.
*/ */
function farm_log_movement_asset_move_action_form(array $context, array $form_state) { function farm_movement_asset_move_action_form(array $context, array $form_state) {
// Date field. // Date field.
$form['date'] = array( $form['date'] = array(
@ -421,7 +421,7 @@ function farm_log_movement_asset_move_action_form(array $context, array $form_st
} }
/** /**
* Submit handler for farm_log_movement_asset_move action configuration form. * Submit handler for farm_movement_asset_move action configuration form.
* *
* @param array $form * @param array $form
* The form array. * The form array.
@ -431,13 +431,13 @@ function farm_log_movement_asset_move_action_form(array $context, array $form_st
* @return array * @return array
* Returns an array that will end up in the action's context. * Returns an array that will end up in the action's context.
*/ */
function farm_log_movement_asset_move_action_submit(array $form, array $form_state) { function farm_movement_asset_move_action_submit(array $form, array $form_state) {
// Start to build the context array. // Start to build the context array.
$context = array(); $context = array();
// Load the areas. // Load the areas.
$context['areas'] = farm_log_movement_parse_areas($form_state['values']['areas']); $context['areas'] = farm_movement_parse_areas($form_state['values']['areas']);
// Convert the date to a timestamp. // Convert the date to a timestamp.
$timestamp = strtotime($form_state['values']['date']); $timestamp = strtotime($form_state['values']['date']);
@ -461,7 +461,7 @@ function farm_log_movement_asset_move_action_submit(array $form, array $form_sta
} }
/** /**
* Action function for farm_log_movement_asset_move. * Action function for farm_movement_asset_move.
* *
* Creates a new movement activity log for the specified assets. * Creates a new movement activity log for the specified assets.
* *
@ -470,7 +470,7 @@ function farm_log_movement_asset_move_action_submit(array $form, array $form_sta
* @param array $context * @param array $context
* Array with parameters for this action. * Array with parameters for this action.
*/ */
function farm_log_movement_asset_move_action(array $assets, $context = array()) { function farm_movement_asset_move_action(array $assets, $context = array()) {
// If we're missing assets, areas, or a timestamp, bail. // If we're missing assets, areas, or a timestamp, bail.
if (empty($assets) || empty($context['areas']) || empty($context['timestamp'])) { if (empty($assets) || empty($context['areas']) || empty($context['timestamp'])) {
@ -479,7 +479,7 @@ function farm_log_movement_asset_move_action(array $assets, $context = array())
} }
// Create a movement activity log. // Create a movement activity log.
farm_log_movement_create($assets, $context['areas'], $context['timestamp'], 'farm_activity', $context['done']); farm_movement_create($assets, $context['areas'], $context['timestamp'], 'farm_activity', $context['done']);
} }
/** /**
@ -497,7 +497,7 @@ function farm_log_movement_asset_move_action(array $assets, $context = array())
* Boolean indicating whether or not the log should be marked "done". Defaults * Boolean indicating whether or not the log should be marked "done". Defaults
* to TRUE. * to TRUE.
*/ */
function farm_log_movement_create($assets, $areas = array(), $timestamp = REQUEST_TIME, $log_type = 'farm_observation', $done = TRUE) { function farm_movement_create($assets, $areas = array(), $timestamp = REQUEST_TIME, $log_type = 'farm_observation', $done = TRUE) {
// If $assets isn't an array, wrap it. // If $assets isn't an array, wrap it.
if (!is_array($assets)) { if (!is_array($assets)) {

View File

@ -1,25 +1,25 @@
<?php <?php
/** /**
* @file * @file
* Code for the Farm Log: Movement feature. * Farm movement.
*/ */
// Include Features code. // Include Features code.
include_once 'farm_log_movement.features.inc'; include_once 'farm_movement.features.inc';
// Include Asset Location code. // Include Asset Location code.
include_once 'farm_log_movement.location.inc'; include_once 'farm_movement.location.inc';
/** /**
* Implements hook_farm_ui_entity_views(). * Implements hook_farm_ui_entity_views().
*/ */
function farm_log_movement_farm_ui_entity_views($entity_type, $bundle, $entity) { function farm_movement_farm_ui_entity_views($entity_type, $bundle, $entity) {
$views = array(); $views = array();
// Add asset movements View at the bottom of assets. // Add asset movements View at the bottom of assets.
if ($entity_type == 'farm_asset') { if ($entity_type == 'farm_asset') {
$views[] = array( $views[] = array(
'name' => 'farm_log_movement', 'name' => 'farm_movement_log',
'weight' => 100, 'weight' => 100,
); );
} }
@ -40,24 +40,24 @@ function farm_log_movement_farm_ui_entity_views($entity_type, $bundle, $entity)
/** /**
* Implements hook_entity_presave(). * Implements hook_entity_presave().
*/ */
function farm_log_movement_entity_presave($entity, $type) { function farm_movement_entity_presave($entity, $type) {
// When a movement field collection entity is being saved, populate the // When a movement field collection entity is being saved, populate the
// geometry field from the "move to" area reference field. // geometry field from the "move to" area reference field.
if ($type == 'field_collection_item' && $entity->field_name == 'field_farm_movement') { if ($type == 'field_collection_item' && $entity->field_name == 'field_farm_movement') {
farm_log_movement_populate_geometry($entity); farm_movement_populate_geometry($entity);
} }
// When a log is being saved, populate the "move from" field with current // When a log is being saved, populate the "move from" field with current
// asset location(s). // asset location(s).
if ($type == 'log') { if ($type == 'log') {
farm_log_movement_populate_move_from($entity); farm_movement_populate_move_from($entity);
} }
// If an activity log is being saved with movement information, auto-fill the // If an activity log is being saved with movement information, auto-fill the
// log title. // log title.
if ($type == 'log' && $entity->type == 'farm_activity') { if ($type == 'log' && $entity->type == 'farm_activity') {
farm_log_movement_populate_name($entity); farm_movement_populate_name($entity);
} }
} }
@ -70,7 +70,7 @@ function farm_log_movement_entity_presave($entity, $type) {
* *
* @see farm_log_entity_presave(). * @see farm_log_entity_presave().
*/ */
function farm_log_movement_populate_geometry($entity) { function farm_movement_populate_geometry($entity) {
// Define the area field name. // Define the area field name.
$area_field = 'field_farm_move_to'; $area_field = 'field_farm_move_to';
@ -109,7 +109,7 @@ function farm_log_movement_populate_geometry($entity) {
* @param Entity $log * @param Entity $log
* The log entity. * The log entity.
*/ */
function farm_log_movement_populate_move_from($log) { function farm_movement_populate_move_from($log) {
// Create an entity wrapper for the log. // Create an entity wrapper for the log.
$log_wrapper = entity_metadata_wrapper('log', $log); $log_wrapper = entity_metadata_wrapper('log', $log);
@ -149,7 +149,7 @@ function farm_log_movement_populate_move_from($log) {
foreach ($assets as $asset) { foreach ($assets as $asset) {
// Load the asset's current location. // Load the asset's current location.
$areas = farm_log_movement_asset_location($asset); $areas = farm_movement_asset_location($asset);
// Build a list of areas. // Build a list of areas.
if (!empty($areas)) { if (!empty($areas)) {
@ -176,7 +176,7 @@ function farm_log_movement_populate_move_from($log) {
* @param Entity $log * @param Entity $log
* The log entity. * The log entity.
*/ */
function farm_log_movement_populate_name($log) { function farm_movement_populate_name($log) {
// If the log already has a name, bail. // If the log already has a name, bail.
if (!empty($log->name)) { if (!empty($log->name)) {
@ -228,7 +228,7 @@ function farm_log_movement_populate_name($log) {
/** /**
* Implements hook_entity_view_alter(). * Implements hook_entity_view_alter().
*/ */
function farm_log_movement_entity_view_alter(&$build, $type) { function farm_movement_entity_view_alter(&$build, $type) {
// If it's not a farm_asset, or if the entity object is not available, bail. // If it's not a farm_asset, or if the entity object is not available, bail.
if ($type != 'farm_asset' || empty($build['#entity'])) { if ($type != 'farm_asset' || empty($build['#entity'])) {
@ -236,7 +236,7 @@ function farm_log_movement_entity_view_alter(&$build, $type) {
} }
// Generate markup to describe the location. // Generate markup to describe the location.
$output = farm_log_movement_asset_location_markup($build['#entity']); $output = farm_movement_asset_location_markup($build['#entity']);
// Add it to the build array. // Add it to the build array.
$build['location'] = array( $build['location'] = array(

View File

@ -2,13 +2,13 @@
/** /**
* @file * @file
* Farm Log: Movement Views data. * Farm movement views data.
*/ */
/** /**
* Implements hook_views_data_alter(). * Implements hook_views_data_alter().
*/ */
function farm_log_movement_views_data_alter(&$data) { function farm_movement_views_data_alter(&$data) {
$data['farm_asset']['latest_movement'] = array( $data['farm_asset']['latest_movement'] = array(
'title' => t('Latest movement'), 'title' => t('Latest movement'),
@ -16,7 +16,7 @@ function farm_log_movement_views_data_alter(&$data) {
'relationship' => array( 'relationship' => array(
'title' => t('Latest movement'), 'title' => t('Latest movement'),
'help' => t('Relate the farm asset to its latest movement.'), 'help' => t('Relate the farm asset to its latest movement.'),
'handler' => 'farm_log_movement_handler_relationship_location', 'handler' => 'farm_movement_handler_relationship_location',
'base' => 'field_collection_item', 'base' => 'field_collection_item',
'base field' => 'item_id', 'base field' => 'item_id',
'label' => t('Latest movement'), 'label' => t('Latest movement'),

View File

@ -1,13 +1,13 @@
<?php <?php
/** /**
* @file * @file
* farm_log_movement.views_default.inc * farm_movement.views_default.inc
*/ */
/** /**
* Implements hook_views_default_views(). * Implements hook_views_default_views().
*/ */
function farm_log_movement_views_default_views() { function farm_movement_views_default_views() {
$export = array(); $export = array();
$view = new view(); $view = new view();
@ -384,11 +384,11 @@ function farm_log_movement_views_default_views() {
$export['farm_asset_geojson'] = $view; $export['farm_asset_geojson'] = $view;
$view = new view(); $view = new view();
$view->name = 'farm_log_movement'; $view->name = 'farm_movement_log';
$view->description = ''; $view->description = '';
$view->tag = 'farm_log'; $view->tag = 'farm_movement';
$view->base_table = 'log'; $view->base_table = 'log';
$view->human_name = 'Farm Log: Logs with movements'; $view->human_name = 'Farm movement logs';
$view->core = 7; $view->core = 7;
$view->api_version = '3.0'; $view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
@ -749,7 +749,7 @@ function farm_log_movement_views_default_views() {
'page' => 'page', 'page' => 'page',
'default' => 0, 'default' => 0,
); );
$translatables['farm_log_movement'] = array( $translatables['farm_movement_log'] = array(
t('Master'), t('Master'),
t('Logs with movements'), t('Logs with movements'),
t('more'), t('more'),
@ -789,7 +789,7 @@ function farm_log_movement_views_default_views() {
t('Page'), t('Page'),
t('Data export'), t('Data export'),
); );
$export['farm_log_movement'] = $view; $export['farm_movement_log'] = $view;
return $export; return $export;
} }

View File

@ -15,7 +15,7 @@
* views_handler_relationship_entity_reverse * views_handler_relationship_entity_reverse
* views_handler_relationship_node_term_data * views_handler_relationship_node_term_data
*/ */
class farm_log_movement_handler_relationship_location extends views_handler_relationship { class farm_movement_handler_relationship_location extends views_handler_relationship {
/** /**
* {@inheritfoc} * {@inheritfoc}
@ -77,7 +77,7 @@ class farm_log_movement_handler_relationship_location extends views_handler_rela
else { else {
$time = REQUEST_TIME; $time = REQUEST_TIME;
} }
$query = farm_log_movement_asset_movement_query($asset_id_field, $time, $done, 'movement_id'); $query = farm_movement_asset_movement_query($asset_id_field, $time, $done, 'movement_id');
// Build the join definition. // Build the join definition.
$def = $this->definition; $def = $this->definition;

View File

@ -7,7 +7,7 @@ dependencies[] = ctools
dependencies[] = entity dependencies[] = entity
dependencies[] = farm_asset dependencies[] = farm_asset
dependencies[] = farm_fields dependencies[] = farm_fields
dependencies[] = farm_log_movement dependencies[] = farm_movement
dependencies[] = features dependencies[] = features
dependencies[] = field_group dependencies[] = field_group
dependencies[] = file dependencies[] = file

View File

@ -353,7 +353,7 @@ function farm_sensor_area_sensors($area_id, $type = '') {
$query->condition('fa.type', 'sensor'); $query->condition('fa.type', 'sensor');
// Build a sub-select query for determining the latest movement log of assets. // Build a sub-select query for determining the latest movement log of assets.
$subquery = farm_log_movement_asset_movement_query('fa.id'); $subquery = farm_movement_asset_movement_query('fa.id');
// Join the latest movement log for each asset. // Join the latest movement log for each asset.
$query->join('log', 'l', 'l.id = (' . $subquery . ')'); $query->join('log', 'l', 'l.id = (' . $subquery . ')');

View File

@ -106,7 +106,7 @@ function farm_sensor_views_default_views() {
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0; $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10'; $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array( $handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
'action::farm_log_movement_asset_move_action' => array( 'action::farm_movement_asset_move_action' => array(
'selected' => 1, 'selected' => 1,
'skip_confirmation' => 1, 'skip_confirmation' => 1,
'override_label' => 0, 'override_label' => 0,

View File

@ -112,7 +112,7 @@ function farm_soil_compost_views_default_views() {
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0; $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10'; $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array( $handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
'action::farm_log_movement_asset_move_action' => array( 'action::farm_movement_asset_move_action' => array(
'selected' => 1, 'selected' => 1,
'skip_confirmation' => 1, 'skip_confirmation' => 1,
'override_label' => 0, 'override_label' => 0,