Skip to content

Commit

Permalink
Merge branch '10.3.5' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
alicolville authored Apr 18, 2023
2 parents 08cd060 + 29c7a42 commit cc67e55
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 172 deletions.
34 changes: 0 additions & 34 deletions includes/admin-pages/page-help.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,6 @@ function ws_ls_help_page() {
</div>
<?php if ( true === current_user_can( 'manage_options' ) && 'y' === ws_ls_querystring_value('yeken') ) : ?>

<div class="postbox">
<h3 class="hndle"><span><?php echo __( 'Custom Fields: Migrate photos from old system to Custom Fields', WE_LS_SLUG); ?> </span></h3>
<div style="padding: 0px 15px 0px 15px">
<p><?php echo __( 'This will migrate photos from the old system to the new custom fields. It will create a custom field with the key "photo". Note! It will remove any existing migrated photos before re-adding them.', WE_LS_SLUG ); ?></p>
<p><a href="<?php echo esc_url( admin_url( 'admin.php?page=ws-ls-help&yeken=y&photomigrate=y') ); ?>" >Run</a></p>

<?php

ws_ls_log_add('help-page', 'YeKen Tool options shown!' );

if ( 'y' === ws_ls_querystring_value('photomigrate') ) {

ws_ls_log_add('photo-migrate', 'Started manually via help page.' );

// If example Photo meta field doesn't exist, then add it!
ws_ls_meta_fields_photos_create_example_field();

// Do we have Photos to migrate from the old photo system to new?
if ( ws_ls_meta_fields_photos_do_we_need_to_migrate( true ) ) {

ws_ls_meta_delete_migrated();

ws_ls_log_add('photo-migrate', 'Photos have been identified for migrating from old photo system to new!' );

ws_ls_meta_fields_photos_migrate_old( true );

echo '<p><strong>' . __( 'Done. View Log below for further information.', WE_LS_SLUG) . '</strong></p>';
}
}

?>
</div>
</div>

<div class="postbox">
<h3 class="hndle"><span><?php echo __( 'Custom Fields: Migrate measurements from old system to Custom Fields', WE_LS_SLUG); ?> </span></h3>
<div style="padding: 0px 15px 0px 15px">
Expand Down
11 changes: 1 addition & 10 deletions pro-features/plus/meta-fields/activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,7 @@ function ws_ls_activate_meta_fields_activate() {
ws_ls_meta_fields_load_examples();
}

// Do we have Photos to migrate from the old photo system to new?
if ( ws_ls_meta_fields_photos_do_we_need_to_migrate() ) {

// If example Photo meta field doesn't exist, then add it!
ws_ls_meta_fields_photos_create_example_field();

ws_ls_log_add('photo-migrate', 'Photos have been identified for migrating from old photo system to new!' );

ws_ls_meta_fields_photos_migrate_old();
}
ws_ls_meta_fields_photos_create_example_field();

// Do we need to migrate measurements?
ws_ls_migrate_measurements_into_meta_fields();
Expand Down
25 changes: 4 additions & 21 deletions pro-features/plus/meta-fields/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,6 @@ function ws_ls_meta_delete( $entry_id, $meta_field_id ) {
return ( 1 === $result );
}

/**
* Delete previous migrated values
*
* @return bool
*/
function ws_ls_meta_delete_migrated() {

if ( false === is_admin() ) {
return false;
}

global $wpdb;

$result = $wpdb->delete( $wpdb->prefix . WE_LS_MYSQL_META_ENTRY, [ 'migrate' => 1 ], [ '%d' ] );

return ( 1 === $result );
}

/**
* Delete all meta entries for given weight entry
*
Expand Down Expand Up @@ -807,11 +789,12 @@ function ws_meta_fields_value_get( $arguments ) {
$arguments[ 'key' ], $arguments[ 'user-id' ]
);

$value = $wpdb->get_var( $sql );
$value = $wpdb->get_var( $sql );
$data = [ 'error' => false, 'value' => $value ];

ws_ls_cache_user_set( $arguments[ 'user-id' ], $cache_key, $value );
ws_ls_cache_user_set( $arguments[ 'user-id' ], $cache_key, $data );

return [ 'error' => false, 'value' => $value ];
return $data;
}

/**
Expand Down
102 changes: 0 additions & 102 deletions pro-features/plus/meta-fields/functions-photos.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,108 +309,6 @@ function ws_ls_meta_fields_photos_delete_all_photos_for_meta_field( $meta_field_
return $count;
}

/**
* Do we need to migrate old photos over?
*
* @param bool $ignore_previous_run
* @return bool
*/
function ws_ls_meta_fields_photos_do_we_need_to_migrate( $ignore_previous_run = false ) {

if ( false === WS_LS_IS_PRO ) {
return false;
}

$migration_already_done = get_option('ws-ls-meta-fields-photo-migrate-done', false );

// Don't run if we have already performed this!
if ( false === $ignore_previous_run && false === empty( $migration_already_done ) ) {
return false;
}

$old_ids = ws_ls_meta_fields_photos_get_old_ids();

// Do we have any photos?
if ( true === empty( $old_ids ) ) {
return false;
}

return true;
}

/**
* Fetch all entry id / photo id for old photo system
*
* @return mixed
*/
function ws_ls_meta_fields_photos_get_old_ids() {

global $wpdb;
return $wpdb->get_results( 'Select id, photo_id from ' . $wpdb->prefix . WE_LS_TABLENAME . ' where photo_id is not null and photo_id <> "" and photo_id <> 0', ARRAY_A);

}

/**
* Migrate old photos to new meta fields!
* @param bool $ignore_previous_run
*/
function ws_ls_meta_fields_photos_migrate_old( $ignore_previous_run = false ) {

if ( true === ws_ls_meta_fields_photos_do_we_need_to_migrate( $ignore_previous_run ) ) {

$photos_to_migrate = ws_ls_meta_fields_photos_get_old_ids();

ws_ls_log_add('photo-migrate', sprintf( 'There are %d photos that are going to be migrated to the new Meta Fields', count( $photos_to_migrate ) ) );

// Get Photo Meta field
$meta_field = ws_ls_meta_fields_get( 'photo' );

if ( true === empty( $meta_field['id'] ) ){
ws_ls_log_add('photo-migrate-fail', 'Could not find meta field to migrate to!' );
return;
} else {
ws_ls_log_add('photo-migrate', sprintf( 'Found meta field to map to: %d', $meta_field['id'] ) );
}

$migrated = 0;

foreach ( $photos_to_migrate as $photo ) {

// Only migrate images that still exist in media library
if ( true === wp_attachment_is_image( $photo['photo_id'] ) ) {

$data = [
'entry_id' => $photo['id'],
'meta_field_id' => $meta_field['id'],
'value' => $photo['photo_id'],
'migrate' => 1
];

global $wpdb;

$result = $wpdb->insert( $wpdb->prefix . WE_LS_MYSQL_META_ENTRY , $data, [ '%d', '%d', '%s', '%d' ] );

if ( false === $result ) {
ws_ls_log_add('migrate-invalid', sprintf( 'Could not add meta entry for photo: %d', $photo['photo_id'] ) );
} else {
ws_ls_log_add('migrate-valid', sprintf( 'Migrated photo: %d! New entry id: %d', $photo['photo_id'], $wpdb->insert_id ) );
$migrated ++;
}

} else {
ws_ls_log_add('migrate-invalid', sprintf( 'Invalid image or doesn\'t exist - Attachment ID %d', $photo['photo_id'] ) );
}

}

ws_ls_log_add('migrate-completed', sprintf( 'Completed photo migration! Migrated %d photos', $migrated ) );

update_option('ws-ls-meta-fields-photo-migrate-done', true );

}

}

/**
* Create example Photo custom field if needed
*/
Expand Down
2 changes: 0 additions & 2 deletions pro-features/plus/meta-fields/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ function ws_ls_meta_fields_shortcode_accumulator( $user_defined_arguments ) {

$html .= '</div>';


//var_dump($todays_entry);
return $html;

}
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: aliakro
Tags: weight,tracker,chart,bmi,bmr,macronutrient,measure,awards,custom fields,history,measurements,data
Requires at least: 5.7
Tested up to: 6.2
Stable tag: 10.3.6
Stable tag: 10.3.7
Requires PHP: 7.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -152,6 +152,11 @@ Measurements are created using Custom Fields. You can therefore specify the unit

== Changelog ==

= 10.3.7 =

* Bug fix: Fixed PHP error being thrown in [wt-custom-fields-latest] due to caching issue.
* Maintenance: Removed redundant photo migration code (from old system into custom fields). This code was added 4 years ago, if folks haven't updated since then, then I doubt they will be now!

= 10.3.6 =

* Tweaks to readme
Expand Down
4 changes: 2 additions & 2 deletions weight-loss-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Plugin Name: Weight Tracker
* Description: Allow your users to track their weight, body measurements, photos and other pieces of custom data. Display in charts, tables, shortcodes and widgets. Manage their data, issue awards, email notifications, etc! Provide advanced data on Body Mass Index (BMI), Basal Metabolic Rate (BMR), Calorie intake, Harris Benedict Formula, Macronutrients Calculator and more.
* Version: 10.3.6
* Version: 10.3.7
* Requires at least: 5.7
* Tested up to: 6.2
* Requires PHP: 7.2
Expand All @@ -18,7 +18,7 @@
*/

define( 'WS_LS_ABSPATH', plugin_dir_path( __FILE__ ) );
define( 'WE_LS_CURRENT_VERSION', '10.3.6' );
define( 'WE_LS_CURRENT_VERSION', '10.3.7' );
define( 'WE_LS_TITLE', 'Weight Tracker' );
define( 'WE_LS_SLUG', 'weight-loss-tracker' );
define( 'WE_LS_LICENSE_TYPES_URL', 'https://docs.yeken.uk/features.html' );
Expand Down

0 comments on commit cc67e55

Please sign in to comment.