Support » Plugin: CMB2 » Gallery data (file_list) unavailable/empty after database migration

  • Resolved saxpaolo

    (@saxpaolo)


    Hello,
    using a file_list custom metafield I’ve recently experienced an issue after migrate the webiste+database from local to production environment.
    Everything works like a charm but, after site+db migration, of all the CMB2 meta fields I have in my theme it seems that the file_list fields data (used for image galleries) results unavailable. Don’t know actually if I missed something or if it is a bug or whatever…

    This is the code I use to generate the image gallery field:

    function my_gallery_metabox()
    {
        $prefix = 'my_';
    
        $cpt_page_options = new_cmb2_box(array(
            'id' => $prefix . 'single_gallery',
            'title' => __('Gallery', 'text-domain'),
            'object_types' => array('my-cpt'),
            'context' => 'side',
        ));
    
        $cpt_page_options->add_field(array(
            'id' => $prefix . 'gallery_options_files',
            'name' => __('Seleziona/carica immagini', 'text-domain'),
            'desc' => __('desc', 'text-domain'),
            'type' => 'file_list',
            // Optional, override default text strings
            'text' => array(
                'add_upload_files_text' => __('Aggiungi o carica file', 'text-domain'), // default: "Add or Upload Files"
                'remove_image_text' => __('Rimuovi immagine', 'text-domain'), // default: "Remove Image"
                'file_text' => __('File', 'text-domain'), // default: "File:"
                'file_download_text' => __('Scarica', 'text-domain'), // default: "Download"
                'remove_text' => __('Rimuovi', 'text-domain'), // default: "Remove"
            ),
        ));
    }
    • This topic was modified 5 months, 3 weeks ago by .
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    What sort of commands/tools did you use to do the migration? For example did you use something like WP-CLI? Perhaps WP Migrate DB/Migrate DB Pro or Better Search/Replace all by deliciousbrains.com ? Or a general find/replace for the domain?

    Asking because chances are the metadata for your fields were serialized data, and if you did just general find/replace, then the serialized information probably became incorrect and thus the data as a whole got “dropped”.

    Hello Michael, thanks for your prompt reply.
    …actually I’ve used find/replace method via phpMyAdmin, replacing local url with the prod server (UPDATE|SET|REPLACE). Does this procedure do not have effects to serialized data? The fact is that all the CMB2 fields data have been stored, except for the file_list field type.

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    if you did a mysql update statement then it’s going to be the same issue, different way.

    One of the nice things about the tools I mentioned yesterday is that they do handle serialized data where they will check if a column’s value is serialized, unserialize it first, run its change, and then re-serialize before committing the update to the original location.

    Regarding why only some of them were affected, it’s likely a case of it’s the only field type used for your case that stores anything beyond a basic string. For observation and learning sake, let’s have you grab one of your post IDs from your local copy, and open up the database with phpMyAdmin or whatever other local tool you have. Then navigate to your wp_postmeta table and filter down by just that post ID. This way you could see all the meta data associated with that post.

    If they’re all simple strings except for 1 or 2 or so, then what I said above is likely accurate.

    OK got it.
    Actually I thought that a simple sql find/replace procedure was enough – e.g. in a wp_postmeta meta_value, like this one:

    a:12:{
    	i:1373;s:57:"http://local-site-name.test/wp-content/uploads/2019/11/slide_01.jpg";
    	i:1374;s:57:"http://local-site-name.test/wp-content/uploads/2019/11/slide_02.jpg";
    	i:1375;s:57:"http://local-site-name.test/wp-content/uploads/2019/11/slide_03.jpg";
    	i:1376;s:57:"http://local-site-name.test/wp-content/uploads/2019/11/slide_04.jpg";
    	i:1377;s:57:"http://local-site-name.test/wp-content/uploads/2019/11/slide_05.jpg";
    	i:1378;s:57:"http://local-site-name.test/wp-content/uploads/2019/11/slide_06.jpg";
    }

    Anyway, what you wrote is clear

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Sounds like you’re on a good foot forward again. Let us know if anything else comes up.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.