Support » Plugin: Media Sync » Smart File Time not working

  • Resolved Dave McHale

    (@dmchale)


    I’m trying to test this plugin to import a large Media Library from a production site to my new dev site

    The files all have a physical timestamp of September 2019 since that’s when they were last moved on the production server, but they all have organized year/month folders within the uploads folder

    I tried testing 2012, which had a /01 and /07 folder. I did an import saying to do the “Smart File Time”, since the physical timestamp wasn’t going to match the folder structure and this way I figured the Media Library would properly create the files with the January and July 2012 info.

    Instead, all the files imported and show up in my Media Library under March 2020 (right now). It’s as if the “date/time” setting is being ignored and just using the “Default” value for some reason.

    I should note, my development server is running Windows. Is it possible that this is causing an issue when trying to detect timestamps for some reason?

    Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author erolsk8

    (@erolsk8)

    Hi @dmchale, that’s strange and it might be because of Windows server. I see it’s being mentioned in PHP documentation: https://www.php.net/manual/en/function.filemtime.php

    I’m not sure when will I find time to try it out, but for now, there are mode details about this in these topics:

      And there is also a custom hook to overwrite date for each file: media_sync_filter_post_date. Here is an example of function which you can add and then modify the date with it.

      /**
       * Overwrite post date for each file imported with Media Sync plugin.
       *
       * Should return date in this format: "Y-m-d H:i:s".
       *
       * @param string $post_date Date figured out by Media Sync plugin for this file
       * @param string $file_path Absolute path to the file being imported
       * @param string $date_type Selected option telling which date to find [default|file_time|smart_file_time]
       * @return string
       */
      function my_custom_media_sync_post_date($post_date, $file_path, $date_type)
      {
          // Custom logic here
          return $post_date;
      }
      add_filter('media_sync_filter_post_date', 'my_custom_media_sync_post_date', 10, 3);
    Thread Starter Dave McHale

    (@dmchale)

    Thanks so much for the response! I wrote some tests and confirmed that filemtime() DOES seem to be returning the correct timestamps from my files, so I don’t think that’s the issue.

    After looking at it more, my best guess is that on Line 561, preg_match('/(\d{4})\/(\d{2})/', $file_path, $matches); is the culprit for not working on Windows. My slashes are probably going the wrong ways round when it tries to detect the month and year, as indicated by the file paths saved to the database after my test imports yesterday. eg: “http://www.mydomain.dev/wp-content/uploads\2012\01\Winter-2012.pdf”

    I am going to experiment with the media_sync_filter_post_date filter a bit later and do what I’m looking to do on my system. Will post back again with an update afterward!

    Plugin Author erolsk8

    (@erolsk8)

    Oh right! It must be it. I’ll try to find some time to update that regex to detect backslashes as well, though I’m not sure when will that be.

    Thanks for the detailed explanation! And please let me know if you figure it out in the meantime.

    Plugin Author erolsk8

    (@erolsk8)

    Hey @dmchale, there is now a new version (1.1.2) which should solve this “Smart File Time” issue on the Windows server.

    Please let me know if it works for you.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Smart File Time not working’ is closed to new replies.