• Resolved opicron

    (@opicron)


    I think I found out why some things are not working. Most of my images are on a CDN (Digital Ocean Spaces).

    Matching files:
    The few files which were still available local were matched. All images on CDN are not matched.

    I checked the source and see that a lot of filechecks are being done. These will fail on an CDN I guess.

    Any chance we can enable usage of CDNs without having the files local?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter opicron

    (@opicron)

    I added the following code to the plugin, in function sync_media of the file lrsync_core.php.

    if ( !$sync_files ) {
    			
    
    			$post_id = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE guid RLIKE '".$lrinfo->lr_file."'", ARRAY_A );
    
    			if ( count($post_id) == 1)
    			{
    				$wpdb->insert( $table_name,
    					array(
    						'wp_id' => $post_id[0]['ID'],
    						'lr_id' => $lrinfo->lr_id,
    						'lr_file' => $lrinfo->lr_file,
    						'lastsync' => NULL
    					)
    				);
    			}
    			else
    			{
    				$post_id = $wpdb->get_results("SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = '_wp_attached_file' AND meta_value RLIKE '".$lrinfo->lr_file."'", ARRAY_A );
    				if ( count($post_id) == 1)
    				{
    					$wpdb->insert( $table_name,
    						array(
    							'wp_id' => $post_id[0]['post_id'],
    							'lr_id' => $lrinfo->lr_id,
    							'lr_file' => $lrinfo->lr_file,
    							'lastsync' => NULL
    						)
    					);
    				}
    			}
    
    		}

    Now my existing files are linked to the LR files automatically even with new uploads as long as the filenames match.

    Would you be so kind to add an hook to the start of sync_media which I can use to create additional functionality outside the plugin?

    • This reply was modified 6 years, 10 months ago by opicron.
    Thread Starter opicron

    (@opicron)

    PS: Just bought the developer license to support the cause :P.

    Plugin Author Jordy Meow

    (@tigroumeow)

    Thank you so much for supporting the cause ??

    There is actually already this action, so you can hook to it already.

    add_action( "wplr_sync_media", "my_func" );
    
    function myfunc( $lr_info ) {
    }

    You can then use $lr_info->wp_id to get the ID of this Media. The file will have been updated so depending on the plugin you are using to upload to S3, you will need to request to that plugin to replace the file on S3. And that would work ??

    Thread Starter opicron

    (@opicron)

    I saw that hook. But I need an pre_sync hook to make things work. In that hook I can make my own entry in the lrsync table to trigger update instead of add.

    If I use the current hook the add media is already executed.

    Plugin Author Jordy Meow

    (@tigroumeow)

    What if right after the declaration of the function function sync_media( $lrinfo, $tmp_path, $wp_col_id = null ) { you add this? :

    do_action( 'wplr_presync_media', $lrinfo, $tmp_path );

    Does this help? I don’t exactly know how you will make it work on your side, but if the above is enough, I will add it to the plugin as well to make sure you have it.

    Thread Starter opicron

    (@opicron)

    That would be sufficient.

    In that function I will check the if I can match the $lrinfo->lrfile with an file in WP. If no previous sync has been registered I add the sync to the lrsync table myself.

    This will automatically couple files on my setup. Very confenient, linked the 3200 images with this method during the weekend.

    Thanks for this plugin, great work!

    PS: to make this work with CDN I had to disable the file_exist on line 740 and 767 in sync_media_update. As the media does not reside on the webserver.

    An checkbox in the setup could be preferred for these setups. “do not check if file exist on CDN” or maybe another method of checking if an offsite image exists.

    Plugin Author Jordy Meow

    (@tigroumeow)

    Ok, I have added this to the plugin, please add it manually to your side from now, and it will be part of the next release.

    For the file_exists, I would need to make a WP filter for this, so that another plugin could hook in and “check” the presence of this file somewhere else (like a CDN).

    So, with your changes, basically, the plugin would work with S3 Upload? Why don’t make you a little plugin for that maybe? ??

    Thread Starter opicron

    (@opicron)

    When the new version is released I will make an extension for it :D.

    Plugin Author Jordy Meow

    (@tigroumeow)

    Please prepare it a bit in advance, and make the plugin request for it, as it takes a bit of time. I think I will publish this new release of WP/LR Sync soon. Would be awesome!

    Thread Starter opicron

    (@opicron)

    Hi there the extension is working fine still and I have not forgotten to make an plugin out of it. But time is scarce and I have to finish some projects :/. I will release it as an plugin in the coming months though.

    Plugin Author Jordy Meow

    (@tigroumeow)

    Thanks a lot @opicron, glad to see you are still here with that little project in mind ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Images on CDN (Digital Ocean Spaces)’ is closed to new replies.