phpmyadmin/libraries/plugins/import
Michal Čihař 9348d0cb16 Separate adding HTML markup to message from others
We really want this to be explicit for easier review and hiding this in
second parameter of addParam doesn't make it.

Signed-off-by: Michal Čihař <michal@cihar.com>
2016-06-16 13:41:35 +02:00
..
upload Fix class namespace 2016-05-23 17:37:38 +02:00
AbstractImportCsv.php Use new contructor for Group() objects 2016-01-05 15:26:52 +01:00
ImportCsv.php Separate adding HTML markup to message from others 2016-06-16 13:41:35 +02:00
ImportLdi.php Adjust tests to new import code 2016-04-11 17:40:56 +02:00
ImportMediawiki.php Align docs 2016-02-19 22:54:18 +11:00
ImportOds.php Merge branch 'QA_4_6' 2016-02-17 11:33:02 +01:00
ImportShp.php Adjust SHP file import to new code 2016-04-11 17:59:42 +02:00
ImportSql.php Revert "Remove sql data parameter" 2016-02-17 10:59:40 +01:00
ImportXml.php Merge branch 'QA_4_6' 2016-02-17 11:33:02 +01:00
README Correct fix for table import processing 2016-02-17 11:12:08 +01:00
ShapeFile.php Remove side effects in declaration files. 2015-10-27 18:56:40 +01:00
ShapeRecord.php Simplify shape record loading 2016-01-05 12:18:05 +01:00

This directory holds import plugins for phpMyAdmin. Any new plugin should
basically follow the structure presented here. The messages must use our
gettext mechanism, see http://wiki.phpmyadmin.net/pma/Gettext_for_developers.

<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * [Name] import plugin for phpMyAdmin
 *
 * @package    PhpMyAdmin-Import
 * @subpackage [Name]
 */
if (! defined('PHPMYADMIN')) {
    exit;
}

/* Get the import interface */
require_once 'libraries/plugins/PMA\libraries\plugins\ImportPlugin.class.php';

/**
 * Handles the import for the [Name] format
 *
 * @package PhpMyAdmin-Import
 */
class Import[Name] extends PMA\libraries\plugins\ImportPlugin
{
    /**
     * optional - declare variables and descriptions
     *
     * @var type
     */
    private $_myOptionalVariable;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->setProperties();
    }

    /**
     * Sets the import plugin properties.
     * Called in the constructor.
     *
     * @return void
     */
    protected function setProperties()
    {
        $importPluginProperties = new PMA\libraries\properties\plugins\ImportPluginProperties();
        $importPluginProperties->setText('[name]');             // the name of your plug-in
        $importPluginProperties->setExtension('[ext]');         // extension this plug-in can handle
        $importPluginProperties->setOptionsText(__('Options'));

        // create the root group that will be the options field for
        // $importPluginProperties
        // this will be shown as "Format specific options"
        $importSpecificOptions = new
        PMA\libraries\properties\options\groups\OptionsPropertyRootGroup(
            "Format Specific Options"
        );

        // general options main group
        $generalOptions = new PMA\libraries\properties\options\groups\OptionsPropertyMainGroup(
            "general_opts"
        );

        // optional :
        // create primary items and add them to the group
        // type - one of the classes listed in libraries/properties/options/items/
        // name - form element name
        // text - description in GUI
        // size - size of text element
        // len  - maximal size of input
        // values - possible values of the item
        $leaf = new PMA\libraries\properties\options\items\RadioPropertyItem(
            "structure_or_data"
        );
        $leaf->setValues(
            array(
                'structure' => __('structure'),
                'data' => __('data'),
                'structure_and_data' => __('structure and data')
            )
        );
        $generalOptions->addProperty($leaf);

        // add the main group to the root group
        $importSpecificOptions->addProperty($generalOptions);

        // set the options for the import plugin property item
        $importPluginProperties->setOptions($importSpecificOptions);
        $this->properties = $importPluginProperties;
    }

    /**
     * Handles the whole import logic
     *
     * @param array &$sql_data 2-element array with sql data
     *
     * @return void
     */
    public function doImport(&$sql_data = array())
    {
        // get globals (others are optional)
        global $error, $timeout_passed, $finished;

        $buffer = '';
        while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
            $data = PMA_importGetNextChunk();
            if ($data === false) {
                // subtract data we didn't handle yet and stop processing
                $GLOBALS['offset'] -= strlen($buffer);
                break;
            } elseif ($data === true) {
                // Handle rest of buffer
            } else {
                // Append new data to buffer
                $buffer .= $data;
            }
            // PARSE $buffer here, post sql queries using:
            PMA_importRunQuery($sql, $verbose_sql_with_comments, $sql_data);
        } // End of import loop
        // Commit any possible data in buffers
        PMA_importRunQuery('', '', $sql_data);
    }


    // optional:
    /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */


    /**
     * Getter description
     *
     * @return type
     */
    private function _getMyOptionalVariable()
    {
        return $this->_myOptionalVariable;
    }

    /**
     * Setter description
     *
     * @param type $my_optional_variable description
     *
     * @return void
     */
    private function _setMyOptionalVariable($my_optional_variable)
    {
        $this->_myOptionalVariable = $my_optional_variable;
    }
}
?>