[OGRU] DataTables BB Code converter

[OGRU] DataTables BB Code converter 1.0.0 Beta

No permission to download

SAS1024

Active member
SAS1024 submitted a new resource:

[OGRU] DataTables BB Code converter - This addon converts DataTables BB Code to native XF 2.x tables

Description:
This resource can convert old [TH] DataTables BB Code to native XenForo 2.x tables.
It can be useful for migration from XenForo 1.5 to XenForo 2.x

I tried to convert over DataTables BB Code from 1300 messages, and all messages was converted successfully.

How to use it:
  1. Create fresh backup of forum database.
  2. You need to setup DataTables separator in admin panel.
  3. From command line run php cmd.php ogru:datatables:convert
  4. You will get...

Read more about this resource...
 
I have data tables in:
  1. Vaultwiki by @pegasus
  2. Article Management System by @Bob
Sorry, I don't have this addons :(
But if you give me DDL of SQL tables with content data of these addons, I can try to implement support for this content types.
 
For VaultWiki:
  • comment text is stored in xf_vw_comment.pagetext and you can run your operations directly on that field.
  • Assuming the admin created a BB-Code custom-field, that text is stored for most content types in xf_vw_field_content.field_value and you can run your operations directly on that field.

However, wiki content must be compiled from the revision history, so you have to issue a new revision via PHP. Here is an example (not tested). Extra handling has been included to modify custom field values too. Add your conversions where I put !!!! comments:
Code:
$ADMIN_USER_ID = 1; // set this to the user_id of the user who will take credit for these changes
$ADMIN_USER_NAME = 'pegasus'; // set this to the username of the user who will take credit for these changes

$pages = \XF::db()->query("
    SELECT pageid
    FROM xf_vw_page
"); // preferably use limits/paging

while ($rec = $pages->fetch())
{
    $page = \vw_Hard_Core::controller('Fetch')->get('Page', $rec['pageid']);

    if ($page)
    {
        $dm = \vw_Hard_Core::controller('DM')->create('Page', 'SILENT');
        $dm->set_info('is_automated', 1);
        $dm->set_existing($page);

        $canfield = true;
        $exact = false;

        $rules = \vw_Hard_Core::model('TemplatePack')->get_content_rules($page);

        if ($rules AND !empty($rules['value']) AND $rules['value'] == 'exact')
        {
            $exact = true;

            if (empty($rules['customfield']))
            {
                $canfield = false;
            }
        }

        if ($canfield)
        {
            $hascached = \vw_Hard_Core::model('CustomField')->has_cached_values($page);
            $fields = \vw_Hard_Core::model('CustomField')->relevant($page);

            $altvalues = array();
            $oldvalues = array();
            $values = array();

            if ($hascached)
            {
                $oldvalues = \vw_Hard_Core::model('CustomField')->values($page, $fields, false);
                $altvalues = \vw_Hard_Core::model('CustomField')->values($page, $fields, true);
                $values = $oldvalues;

                foreach ($fields AS $fieldid => $field)
                {
                    switch ($field['fieldtype'])
                    {
                        case 'bbcode':
                            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                                                             
                            // DO YOUR DATATABLES CONVERSION MAGIC HERE
                            // $values[$fieldid] = str_replace('[datatable]', '[table]', $values[$fieldid]);
                            break;
                    }              
                }
            }

            $dm->set_info('old_custom_field_values', $oldvalues);
            $dm->set_info('new_custom_field_values', $values);
            $dm->set_info('alt_custom_field_values', $altvalues);

            if (!empty($page['templateid']) AND !$exact)
            {
                $oldtplvalues = array();
                $tplvalues = array();

                if ($hascached)
                {
                    $tplfields = \vw_Hard_Core::model('CustomField')->templates($page);
                    $oldtplvalues = \vw_Hard_Core::model('CustomField')->values($page, $tplfields, false);
                    $tplvalues = $oldtplvalues;

                    foreach ($tplfields AS $tplfieldid => $tplfield)
                    {
                        switch ($tplfield['fieldtype'])
                        {
                            case 'bbcode':
                                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                                                             
                                // DO YOUR DATATABLES CONVERSION MAGIC HERE
                                // $tplvalues[$tplfieldid] = str_replace('[datatable]', '[table]', $tplvalues[$tplfieldid]);
                                break;
                        }
                    }
                }

                $dm->set_info('old_template_field_values', $oldtplvalues);
                $dm->set_info('new_template_field_values', $tplvalues);
            }
        }

        $dm->set_info('revision_visible', 1);

        $dm->set('userid', $ADMIN_USER_ID);
        $dm->set('username', $ADMIN_USER_NAME);
        $dm->set('reason', 'converted datatables to TABLE bb-code');

        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                                                             
        // DO YOUR DATATABLES CONVERSION MAGIC HERE
        // $page['pagetext'] = str_replace('[datatable]', '[table]', $page['pagetext']);

        $dm->set('pagetext', $page['pagetext']);
        $dm->process_custom_fields();

        $dm->save();
        unset($dm);
    }
}

EDIT: During some testing I noticed that the new_custom_field_values expects a different input format than old_custom_field_values (old goes into existing-data but new just goes to set the value). Here is a helper method:
Code:
protected function flatten_new_values($newvalues)
{
    $out = array();

    foreach ($newvalues AS $k => $value)
    {
        if (is_array($value) AND isset($value['field_value']))
        {
            $out["$k"] = $value['field_value'];
        }
        else
        {
            $out["$k"] = $value;
        }
    }

    return $out;
}
Where above has $values = $oldvalues; and $tplvalues = $oldtplvalues;, you should instead do something like:
Code:
$values = $this->flatten_new_values($oldvalues);
Code:
$tplvalues = $this->flatten_new_values($oldtplvalues);
Sorry for not noticing this sooner.
 
Last edited:
Top Bottom