ThorntonStuart / SimpleCloner

An entry cloning module compatible with EE3
5 stars 3 forks source link

Add support for Ansel, and fix a couple bugs in bloqs and relationships #5

Closed matthewjohns0n closed 7 years ago

tjdraper commented 7 years ago

If I may butt in here. This PR assumes Ansel is installed. If Ansel is not installed, EE throws a big fit about trying to select from a table that does not exist.

It also assumes Assets is installed (added prior to this PR).

The fix is as follows:

Down on line 283 of ext.simple_cloner.php, change the Ansel support to the following.

$ansel = ee('Addon')->get('ansel');

if ($ansel && $ansel->isInstalled()) {
    $ansel_images = ee()->db->query('SELECT * FROM exp_ansel_images WHERE content_id = ' . $data['entry_id'] . ' AND content_type = "channel"');

    $this->duplicate_ansel($ansel_images, $entry_id_of_duplicate);
}

And the same business for assets support right under.

$assets = ee('Addon')->get('assets');

if ($assets && $assets->isInstalled()) {
    $assets_selections = ee()->db->query('SELECT * FROM exp_assets_selections WHERE entry_id = '.$data['entry_id'].' AND content_type IS NULL');

    if ($assets_selections->num_rows != 0){
        $all_assets = $assets_selections->result();
        foreach($all_assets as $kee => $vals) {
            $prop = get_object_vars($vals);
            $prop['entry_id'] = $entry_id_of_duplicate;
            ee()->db->insert('assets_selections', $prop);
        }
    }
}

I’d make these changes and submit to the PR myself but I don’t think I, as a third party, can modify or add to an open PR? Or maybe I don’t know how to do it.

tjdraper commented 7 years ago

Just discovered, same is going to go for Assets and Ansel support in grid:

if ($assets && $assets->isInstalled()) {
    $assets_selections = ee()->db->query('SELECT * FROM exp_assets_selections WHERE entry_id = '.$data['entry_id'].' AND content_type = "grid" AND row_id ='.$save_row_id);
    if ($assets_selections->num_rows != 0){
        $all_assets = $assets_selections->result();
        foreach($all_assets as $kee => $vals){
            $prop = get_object_vars($vals);
            $prop['entry_id'] = $entry_id_of_duplicate;
            $prop['row_id'] = $new_row_id;
            ee()->db->insert('assets_selections', $prop);
        }
    }
}

// Ansel support
if ($ansel && $ansel->isInstalled()) {
    $ansel_images = ee()->db->query('SELECT * FROM exp_ansel_images WHERE content_id = '.$data['entry_id'].' AND content_type = "grid" AND row_id ='.$save_row_id);
    $this->duplicate_ansel($ansel_images, $entry_id_of_duplicate, $new_row_id);
}
matthewjohns0n commented 7 years ago

Thanks TJ, good catch. I added those checks in.

ThorntonStuart commented 7 years ago

Hi guys. Thanks for your contributions. I will review this tomorrow and hopefully should be good to merge.