<?php

/**
 * This Software is the property of Data Development and is protected
 * by copyright law - it is NOT Freeware.
 *
 * Any unauthorized use of this software without a valid license
 * is a violation of the license agreement and will be prosecuted by
 * civil and criminal law.
 *
 * http://www.shopmodule.com
 *
 * @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
 * @author    D3 Data Development - Daniel Seifert <support@shopmodule.com>
 * @link      http://www.oxidmodule.com
 */

/**
 * Class d3_extsearch_update
 */
class d3_extsearch_update extends d3install_updatebase
{
    public $sModKey = 'd3_extsearch';
    public $sModName = 'erweiterte Suche';
    public $sModVersion = '5.5.3.1';
    public $sModRevision = '1057';
    public $sBaseConf = '8P0ck4zNEppcnJXQVVoRlNiczVwcTFnc2JrTVg1OE1wWHN6ZGRwVkFPR1hJTUQ4ZWVvNU5jUDRTOUZNV
nlYUVd0cXI5VHNWSFNIbHFIakg2U2R3eVZlSGtjMWEvcmxsS0FWS2JQRmdNU0htMkxyUlplelFRTERyN
DNDYXlYL1lZbjJRMFBFSHZNMEc2Tk5YNm93Q0ZxbTVSMnVrT3FYcWVNSDRsTHMxc2lkdk9jaU5yOTcyV
zRzemFpOGNqVWdPWnJoY25PRGtSVG1MSlhkOW1JYlRQT1JhNUIveWVCZG1pVCs0dXU2eW9uTGE2VWVKR
nJSS211cmZVNktVVlhYWGxzV3dDeFR3dCtVUUJPdlJ5aEhFM1BNVFA1dmsvVlhVU1ZVdGEyT2N3OFFOM
Xc9';
    public $sRequirements = '';
    public $sBaseValue = 'TyUzQTglM0ElMjJzdGRDbGFzcyUyMiUzQTU5JTNBJTdCcyUzQTI4JTNBJTIyZDNfY2ZnX21vZF9fYUxp
Y2Vuc2VJbmZvTWFpbCUyMiUzQmElM0EyJTNBJTdCcyUzQTQyJTNBJTIyTk9MSUNLRVlfXzQ3OTM2Mzg3MDJiNjc3MTVmMWRmYmZjOD
MyNDY2OTE0JTIyJTNCcyUzQTE5JTNBJTIyMjAxMy0wMS0xNiUyMDEyJTNBMTAlM0E0MCUyMiUzQnMlM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JTNBJTIyMCUyMiUzQnMlM0EzMyUzQSUyMmQzX2
NmZ19tb2RfX2JsRXh0U2VhcmNoX1Nob3dQb3B1cCUyMiUzQnMlM0ExJTNBJTIyMCUyMiUzQnMlM0E0OCUzQSUyMmQzX2NmZ19tb2Rf
X2JsRXh0U2VhcmNoX1ZhcmlhbnRDaGVja1BhcmVudEFjdGl2ZSUyMiUzQnMlM0ExJTNBJTIyMCUyMiUzQiU3RA==';

    protected $_aUpdateMethods = array(
        array('check' => 'checkModCfgItemExist',
              'do'    => 'updateModCfgItemExist'),
        array('check' => 'checkRenameFields',
              'do'    => 'fixRenameFields'),
        array('check' => 'checkDeleteFields',
              'do'    => 'fixDeleteFields'),
        array('check' => 'checkIndexRefreshMsg',
              'do'    => 'fixIndexRefreshMsg'),
        array('check' => 'checkSynsetTablesExist',
              'do'    => 'addSynsetTables'),
        array('check' => 'checkFields',
              'do'    => 'fixFields'),
        array('check' => 'checkIndizes',
              'do'    => 'fixIndizes'),
        array('check' => 'checkContentNoArtItemExist',
              'do'    => 'updateContentNoArtItemExist'),
        array('check' => 'hasUnregisteredFiles',
              'do'    => 'showUnregisteredFiles'),
        array('check' => 'checkModCfgSameRevision',
              'do'    => 'updateModCfgSameRevision'),
    );

    public $aFields = array(
        'D3_PHONETIC'        => array(
            'sTableName'  => 'oxartextends',
            'sFieldName'  => 'D3_PHONETIC',
            'sType'       => 'LONGTEXT',
            'blNull'      => false,
            'sDefault'    => false,
            'sComment'    => 'modExtSearch',
            'sExtra'      => '',
            'blMultilang' => true,
        ),
        'D3_SEARCHINDEXDATE' => array(
            'sTableName'  => 'oxarticles',
            'sFieldName'  => 'D3_SEARCHINDEXDATE',
            'sType'       => 'DATETIME',
            'blNull'      => false,
            'sDefault'    => '0000-00-00 00:00:00',
            'sComment'    => 'modExtSearch',
            'sExtra'      => '',
            'blMultilang' => true,
        ),
        'D3PUSH'             => array(
            'sTableName'  => 'oxarticles',
            'sFieldName'  => 'D3PUSH',
            'sType'       => 'TINYINT(1)',
            'blNull'      => false,
            'sDefault'    => '1',
            'sComment'    => 'search sort criteria',
            'sExtra'      => '',
            'blMultilang' => false,
        ),
        'D3COUNT'            => array(
            'sTableName'  => 'oxlogs',
            'sFieldName'  => 'D3COUNT',
            'sType'       => 'INT(5)',
            'blNull'      => false,
            'sDefault'    => '0',
            'sComment'    => 'modExtSearch',
            'sExtra'      => '',
            'blMultilang' => false,
        ),
        'D3ISSEARCHABLE'     => array(
            'sTableName'  => 'oxcontents',
            'sFieldName'  => 'D3ISSEARCHABLE',
            'sType'       => 'TINYINT(1)',
            'blNull'      => false,
            'sDefault'    => '0',
            'sComment'    => 'modExtSearch',
            'sExtra'      => '',
            'blMultilang' => false,
        ),
        'D3NOTUSE4FILTER'    => array(
            'sTableName'  => 'oxattribute',
            'sFieldName'  => 'D3NOTUSE4FILTER',
            'sType'       => 'TINYINT(1)',
            'blNull'      => false,
            'sDefault'    => '0',
            'sComment'    => 'attrib use in extsearch',
            'sExtra'      => '',
            'blMultilang' => false,
        ),
        'D3NOTUSE4FILTERCAT'    => array(
            'sTableName'  => 'oxcategories',
            'sFieldName'  => 'D3NOTUSE4FILTER',
            'sType'       => 'TINYINT(1)',
            'blNull'      => false,
            'sDefault'    => '0',
            'sComment'    => 'category use in extsearch',
            'sExtra'      => '',
            'blMultilang' => false,
        ),
    );

    public $aIndizes = array(
        'D3COUNT' => array(
            'sTableName' => 'oxlogs',
            'sType'      => '',
            'sName'      => 'D3COUNT',
            'aFields'    => array(
                'D3COUNT' => 'D3COUNT',
            ),
        ),
    );

    public $aRenameFields = array(
        'D3_PHONETIC'        => array(
           'sTableName'  => 'oxarticles',
           'mOldFieldNames' => array('d3_phonetic'), // is case sensitive
           'sFieldName'  => 'D3_PHONETIC',
           'blMultilang' => true,
        ),
        'D3_SEARCHINDEXDATE'        => array(
           'sTableName'  => 'oxarticles',
           'mOldFieldNames' => array('d3_searchIndexDate'), // is case sensitive
           'sFieldName'  => 'D3_SEARCHINDEXDATE',
           'blMultilang' => true,
        ),
        'D3PUSH'        => array(
           'sTableName'  => 'oxarticles',
           'mOldFieldNames' => array('d3push'), // is case sensitive
           'sFieldName'  => 'D3PUSH',
           'blMultilang' => false,
        ),
        'D3NOTUSE4FILTER'        => array(
           'sTableName'  => 'oxattribute',
           'mOldFieldNames' => array('d3notuse4filter'), // is case sensitive
           'sFieldName'  => 'D3NOTUSE4FILTER',
           'blMultilang' => false,
        ),
    );

    public $aSemanticTables = array();

    public $aOldModuleFiles = array(
        'd3/d3_extsearch/models/d3_extsearch_update.php',
    );

    protected $_aRefreshMetaModuleIds = array('d3_extsearch');

    /**
     * constructor
     */
    public function __construct()
    {
        require_once('d3_extsearch_semanticstructure.php');

        parent::__construct();
    }

    /**
     * @return bool
     */
    public function checkModCfgItemExist()
    {
        $blRet = false;
        foreach ($this->getShopList() as $oShop) {
            /** @var $oShop oxshop */
            $aWhere = array(
                'oxmodid'       => $this->sModKey,
                'oxnewrevision' => $this->sModRevision,
                'oxshopid'      => $oShop->getId(),
            );

            $blRet = $this->_checkTableItemNotExist('d3_cfg_mod', $aWhere);

            if ($blRet) {
                return $blRet;
            }
        }

        return $blRet;
    }

    /**
     * @return bool
     */
    public function updateModCfgItemExist()
    {
        $blRet = false;

        if ($this->checkModCfgItemExist()) {
            $this->setInitialExecMethod(__METHOD__);

            foreach ($this->getShopList() as $oShop) {
                /** @var $oShop oxshop */
                $aWhere = array(
                    'oxmodid'       => $this->sModKey,
                    'oxshopid'      => $oShop->getId(),
                    'oxnewrevision' => $this->sModRevision,
                );

                if ($this->_checkTableItemNotExist('d3_cfg_mod', $aWhere)) {
                    // update don't use this property
                    unset($aWhere['oxnewrevision']);

                    $aInsertFields = array(
                        'OXID'           => array (
                            'content'       => "md5('" . $this->sModKey . " " . $oShop->getId() . " de')",
                            'force_update'  => true,
                            'use_quote'     => false,
                        ),
                        'OXSHOPID'       => array (
                            'content'       => $oShop->getId(),
                            'force_update'  => true,
                            'use_quote'     => true,
                        ),
                        'OXMODID'        => array (
                            'content'       => $this->sModKey,
                            'force_update'  => true,
                            'use_quote'     => true,
                        ),
                        'OXNAME'         => array (
                            'content'       => $this->sModName,
                            'force_update'  => true,
                            'use_quote'     => true,
                        ),
                        'OXACTIVE'       => array (
                            'content'       => "0",
                            'force_update'  => false,
                            'use_quote'     => false,
                        ),
                        'OXBASECONFIG'   => array (
                            'content'       => $this->sBaseConf,
                            'force_update'  => true,
                            'use_quote'     => true,
                        ),
                        'OXSERIAL'   => array (
                            'content'       => "",
                            'force_update'  => false,
                            'use_quote'     => true,
                        ),
                        'OXINSTALLDATE'  => array (
                            'content'       => "NOW()",
                            'force_update'  => true,
                            'use_quote'     => false,
                        ),
                        'OXVERSION'      => array (
                            'content'       => $this->sModVersion,
                            'force_update'  => true,
                            'use_quote'     => true,
                        ),
                        'OXSHOPVERSION'  => array (
                            'content'       => oxRegistry::getConfig()->getEdition(),
                            'force_update'  => true,
                            'use_quote'     => true,
                        ),
                        'OXREQUIREMENTS' => array (
                            'content'       => $this->sRequirements,
                            'force_update'  => true,
                            'use_quote'     => true,
                        ),
                        'OXVALUE'        => array(
                            'content'       => $this->sBaseValue,
                            'force_update'  => false,
                            'use_quote'     => true,
                        ),
                        'OXNEWREVISION'  => array(
                            'content'       => $this->sModRevision,
                            'force_update'  => true,
                            'use_quote'     => true,
                        )
                    );

                    $this->setInitialExecMethod(__METHOD__);
                    $blRet  = $this->_updateTableItem2('d3_cfg_mod', $aInsertFields, $aWhere);
                }
            }
        }
        return $blRet;
    }

    /**
     * config example:
     *  public $aDeleteFields = array(
     *      'D3_PHONETIC'        => array(
     *          'sTableName'  => 'oxarticles',
     *          'sFieldName'  => 'D3_PHONETIC',
     *          'blMultilang' => true,
     *       ),
     *  );
     *
     * @return bool
     */
    public function checkDeleteFields()
    {
        $blReturn = false;

        $blCS = false; // search is case sensitive

        if ($this->aDeleteFields && is_array($this->aDeleteFields) && count($this->aDeleteFields)) {
            foreach ($this->aDeleteFields as $aField) {
                $iChangeLang = $aField['blMultilang'] ? 15 : 0;
                for ($iLang=$iChangeLang; $iLang >= 0; $iLang--) {
                    $sCheckName = $this->_addMultiLangAddOn($aField['sFieldName'], $iLang);
                    $sMLTableName = getLangTableName($aField['sTableName'], $iLang);
                    $blReturn = $this->_checkTableFieldExist($sMLTableName, $sCheckName, $blCS);

                    if ($blReturn) {
                        return $blReturn;
                    }
                }
            }
        }

        return $blReturn;
    }

    /**
     * config example:
     *  public $aDeleteFields = array(
     *      'D3_PHONETIC'        => array(
     *          'sTableName'  => 'oxarticles',
     *          'sFieldName'  => 'D3_PHONETIC',
     *          'blMultilang' => true,
     *       ),
     *  );
     *
     * @param string $sMethodName
     *
     * @return bool
     */
    public function fixDeleteFields($sMethodName = __METHOD__)
    {
        $blReturn = true;

        if ($this->aDeleteFields && is_array($this->aDeleteFields) && count($this->aDeleteFields)) {
            foreach ($this->aDeleteFields as $aField) {
                $iChangeLang = $aField['blMultilang'] ? 15 : 0;
                for ($iLang=$iChangeLang; $iLang >= 0; $iLang--) {
                    $sCheckName = $this->_addMultiLangAddOn($aField['sFieldName'], $iLang);
                    $sMLTableName = getLangTableName($aField['sTableName'], $iLang);
                    if ($this->_checkTableFieldExist($sMLTableName, $sCheckName, $blCS = false)) {
                        $blReturn = $this->_dropTableField($sMLTableName, $sCheckName, $sMethodName);

                        $sFieldName = 'D3_SEARCHINDEXDATE';
                        $sIndexCheckName = $this->_addMultiLangAddOn($sFieldName, $iLang);

                        if ($this->_checkTableFieldExist($sMLTableName, $sIndexCheckName, $blCS = false)) {
                            $aWhere = array(
                                'oxactive'      => '1',
                            );

                            $aUpdateFields = array(
                                $sIndexCheckName       => array(
                                    'fieldname'    => $sIndexCheckName,
                                    'content'      => '0000-00-00',
                                    'force_update' => true,
                                    'use_quote'    => true,
                                ),
                            );

                            $this->setInitialExecMethod(__METHOD__);
                            $blReturn  = $this->_updateTableItem2($sMLTableName, $aUpdateFields, $aWhere);

                            oxRegistry::getSession()->setVariable('checkIndexRefreshMsg', true);
                        }
                    }
                }
            }
        }

        return $blReturn;
    }

    /**
     * @return bool
     */
    public function checkIndexRefreshMsg()
    {
        if (oxRegistry::getSession()->getVariable('checkIndexRefreshMsg')) {
            return true;
        }

        return false;
    }

    /**
     * @return bool
     */
    public function fixIndexRefreshMsg()
    {
        $blRet = true;

        if (oxRegistry::getSession()->getVariable('checkIndexRefreshMsg')) {
            oxRegistry::getSession()->setVariable('checkIndexRefreshMsg', false);
            $this->_confirmMessage('D3_EXTSEARCH_UPDATE_GENPHONETIC');
        }

        return $blRet;
    }

    /**
     * @return bool
     */
    public function checkContentNoArtItemExist()
    {
        $blRet = false;
        foreach ($this->getShopList() as $oShop) {
            /** @var $oShop oxshop */
            $aWhere = array(
                'oxloadid' => 'd3extsearch_noarticlefound',
                'oxshopid' => $oShop->getId(),
            );

            $blRet = $this->_checkTableItemNotExist('oxcontents', $aWhere);

            if ($blRet) {
                return $blRet;
            }
        }

        return $blRet;
    }

    /**
     * @return bool
     */
    public function updateContentNoArtItemExist()
    {
        $blRet = false;

        foreach ($this->getShopList() as $oShop) {
            /** @var $oShop oxshop */
            $aWhere = array(
                'oxloadid' => 'd3extsearch_noarticlefound',
                'oxshopid' => $oShop->getId(),
            );

            if ($this->_checkTableItemNotExist('oxcontents', $aWhere)) {
                $aWhere = array();
                $aInsertFields = array(
                    array (
                        'fieldname'     => 'OXID',
                        'content'       => "md5('d3extsearch_noarticlefound " . $oShop->getId() . "')",
                        'force_update'  => true,
                        'use_quote'     => false,
                    ),
                    array (
                        'fieldname'     => 'OXLOADID',
                        'content'       => "d3extsearch_noarticlefound",
                        'force_update'  => true,
                        'use_quote'     => true,
                    ),
                    array (
                        'fieldname'     => 'OXSHOPID',
                        'content'       => $oShop->getId(),
                        'force_update'  => true,
                        'use_quote'     => true,
                    ),
                    array (
                        'fieldname'     => 'OXSNIPPET',
                        'content'       => "1",
                        'force_update'  => true,
                        'use_quote'     => true,
                    ),
                    array (
                        'fieldname'     => 'OXTYPE',
                        'content'       => "0",
                        'force_update'  => true,
                        'use_quote'     => true,
                    ),
                    array (
                        'fieldname'     => 'OXACTIVE',
                        'content'       => "1",
                        'force_update'  => false,
                        'use_quote'     => true,
                        'use_multilang' => true,
                    ),
                    array (
                        'fieldname'     => 'OXPOSITION',
                        'content'       => "",
                        'force_update'  => true,
                        'use_quote'     => true,
                    ),
                    array (
                        'fieldname'     => $this->_getLangAbbrFieldName('oxcontents', 'OXTITLE', 'de'),
                        'content'       => "Leider wurden keine Artikel gefunden",
                        'force_update'  => false,
                        'use_quote'     => true,
                        'use_multilang' => true,
                    ),
                    array (
                        'fieldname'     => 'OXCONTENT',
                        'content'       => "<p>Versuchen Sie es mit einem anderen Suchbegriff, einer anderen ".
                            "Schreibweise oder anderen Filtern bitte noch einmal. </p><p>Erhalten Sie dennoch keine ".
                            "Ergebnisse, kontaktieren Sie uns bitte ".
                            "<a href=\"[{oxgetseourl ident=\$oViewConf->getSelfLink()|cat:\"cl=contact\"}]\">hier</a>.".
                            "</p><br />",
                        'force_update'  => false,
                        'use_quote'     => true,
                        'use_multilang' => true,
                    ),
                    array (
                        'fieldname'     => $this->_getLangAbbrFieldName('oxcontents', 'OXTITLE', 'en'),
                        'content'       => "Sorry, no items were found.",
                        'force_update'  => false,
                        'use_quote'     => true,
                    ),
                    array (
                        'fieldname'     => 'OXCATID',
                        'content'       => "kgo83a794223bfd23cbb091d0a34019d",
                        'force_update'  => true,
                        'use_quote'     => true,
                    ),
                    array (
                        'fieldname'     => 'OXFOLDER',
                        'content'       => "CMSFOLDER_USERINFO",
                        'force_update'  => true,
                        'use_quote'     => true,
                    ),
                );

                $this->setInitialExecMethod(__METHOD__);
                $blRet  = $this->_updateTableItem2('oxcontents', $aInsertFields, $aWhere);

                if ($this->getStepByStepMode()) {
                    break;
                }
            }
        }

        return $blRet;
    }

    /**
     * @return bool true, if table is missing
     */
    public function checkSynsetTablesExist()
    {
        foreach ($this->aSemanticTables as $aSemanticTable) {
            if (($blRet = $this->_checkTableNotExist($aSemanticTable['sName']))) {
                return $blRet;
            };
        }

        return false;
    }

    /**
     * @return bool
     */
    public function addSynsetTables()
    {
        $this->setInitialExecMethod(__METHOD__);

        $blDoRet = false;
        foreach ($this->aSemanticTables as $aSemanticTable) {
            if (($blRet = $this->_checkTableNotExist($aSemanticTable['sName']))) {

                if ($this->hasExecute()) {
                    $iCount = $this->getUpdateStepCount();
                    oxRegistry::getSession()->setVariable('iD3UpdatebaseCount', $iCount + 1);
                    oxRegistry::getSession()->setVariable(
                        'sD3UpdatebaseStepDesc',
                        sprintf(
                            oxRegistry::getLang()->translateString('D3_EXTSEARCH_SETUP_ADDTABLE'),
                            $aSemanticTable['sName']
                        )
                    );
                }

                $blDoRet = $this->_addTable2(
                    $aSemanticTable['sName'],
                    $this->aFields,
                    $this->aIndizes,
                    $aSemanticTable['sComment'],
                    $aSemanticTable['sType']
                );

                if ($this->getUpdateBreak() || false == $blDoRet) {
                    return $blDoRet;
                }
            }
        }

        return $blDoRet;
    }

    /**
     * @return bool
     */
    public function hasUnregisteredFiles()
    {
        return $this->_hasUnregisteredFiles('d3_extsearch', array('blocks', 'd3FileRegister'));
    }

    /**
     * @return bool
     */
    public function showUnregisteredFiles()
    {
        return $this->_showUnregisteredFiles('d3_extsearch', array('blocks', 'd3FileRegister'));
    }
}
