initialize article

@param string $sHeapTable heap table name
@param int    $iCnt       record number
@param bool   $blContinue false is used to stop exporting

@return object
15438
protected function _initArticle($sHeapTable, $iCnt, & $blContinue)
    {
        $oRs = $this->getDb()->selectLimit("select oxid from $sHeapTable", 1, $iCnt);
        if ($oRs != false && $oRs->count() > 0) {
            $oArticle = oxNew(\OxidEsales\Eshop\Application\Model\Article::class);
            $oArticle->setLoadParentData(true);

            $oArticle->setLanguage(\OxidEsales\Eshop\Core\Registry::getSession()->getVariable("iExportLanguage"));

            if ($oArticle->load($oRs->fields[0])) {
                // if article exists, do not stop export
                $blContinue = true;
                // check price
                $dMinPrice = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("sExportMinPrice");
                if (!isset($dMinPrice) || (isset($dMinPrice) && ($oArticle->getPrice()->getBruttoPrice() >= $dMinPrice))) {
                    //Saulius: variant title added
                    $sTitle = $oArticle->oxarticles__oxvarselect->value ? " " . $oArticle->oxarticles__oxvarselect->value : "";
                    $oArticle->oxarticles__oxtitle->setValue($oArticle->oxarticles__oxtitle->value . $sTitle);

                    $oArticle = $this->updateArticle($oArticle);

                    return $oArticle;
                }
            }
        }
    }
757863
public function createThumbnail($sFileName, $iThumbSize = null, $blCrop = true)
    {
        $sFilePath = $this->getMediaPath($sFileName);

        if (is_readable($sFilePath)) {
            if (!$iThumbSize) {
                $iThumbSize = $this->_iDefaultThumbnailSize;
            }

            list($iImageWidth, $iImageHeight, $iImageType) = getimagesize($sFilePath);

            switch ($iImageType) {
                case 1:
                    $rImg = imagecreatefromgif($sFilePath);
                    break;

                case 2:
                    $rImg = imagecreatefromjpeg($sFilePath);
                    break;

                case 3:
                    $rImg = imagecreatefrompng($sFilePath);
                    break;

                default:
                    throw new \Exception('Invalid filetype');
                    break;
            }

            $iThumbWidth = $iImageWidth;
            $iThumbHeight = $iImageHeight;

            $iThumbX = 0;
            $iThumbY = 0;

            if ($blCrop) {
                if ($iImageWidth < $iImageHeight) {
                    $iThumbWidth = $iThumbSize;
                    $iThumbHeight = $iImageHeight / ($iImageWidth / $iThumbWidth);

                    $iThumbY = (($iThumbSize - $iThumbHeight) / 2);
                } elseif ($iImageHeight < $iImageWidth) {
                    $iThumbHeight = $iThumbSize;
                    $iThumbWidth = $iImageWidth / ($iImageHeight / $iThumbHeight);

                    $iThumbX = (($iThumbSize - $iThumbWidth) / 2);
                }
            } else {
                if ($iImageWidth < $iImageHeight) {
                    if ($iImageHeight > $iThumbSize) {
                        $iThumbWidth *= ($iThumbSize / $iImageHeight);
                        $iThumbHeight *= ($iThumbSize / $iImageHeight);
                    }
                } elseif ($iImageHeight < $iImageWidth) {
                    if ($iImageHeight > $iThumbSize) {
                        $iThumbWidth *= ($iThumbSize / $iImageWidth);
                        $iThumbHeight *= ($iThumbSize / $iImageWidth);
                    }
                }
            }

            $rTmpImg = imagecreatetruecolor($iThumbWidth, $iThumbHeight);
            imagecopyresampled($rTmpImg, $rImg, $iThumbX, $iThumbY, 0, 0, $iThumbWidth, $iThumbHeight, $iImageWidth, $iImageHeight);

            if ($blCrop) {
                $rThumbImg = imagecreatetruecolor($iThumbSize, $iThumbSize);
                imagefill($rThumbImg, 0, 0, imagecolorallocate($rThumbImg, 0, 0, 0));

                imagecopymerge($rThumbImg, $rTmpImg, 0, 0, 0, 0, $iThumbSize, $iThumbSize, 100);
            } else {
                $rThumbImg = $rTmpImg;
            }

            $sThumbName = $this->getThumbName($sFileName, $iThumbSize);

            imagejpeg($rThumbImg, $this->getThumbnailPath($sThumbName));

            return $sThumbName;
        }

        return false;
    }
860965
public void initDocument()
    throws TemplateInitException
    {
        /*
         *  send an empty InternalContextAdapter down into the AST to initialize it
         */

        InternalContextAdapterImpl ica = new InternalContextAdapterImpl(  new VelocityContext() );

        try
        {
            /*
             *  put the current template name on the stack
             */

            ica.pushCurrentTemplateName( name );
            ica.setCurrentResource( this );

            /*
             *  init the AST
             */

            ((SimpleNode)data).init( ica, rsvc);

            String property = scopeName+'.'+RuntimeConstants.PROVIDE_SCOPE_CONTROL;
            provideScope = rsvc.getBoolean(property, provideScope);
        }
        finally
        {
            /*
             *  in case something blows up...
             *  pull it off for completeness
             */

            ica.popCurrentTemplateName();
            ica.setCurrentResource( null );
        }

    }
738611
protected void initDatabaseExportObject() {

        Object o;

        if (CmsStringUtil.isEmpty(getParamAction())) {
            o = new CmsExportParameters();
        } else {
            // this is not the initial call, get the job object from session
            o = getDialogObject();
        }

        if (!(o instanceof CmsExportParameters)) {
            // create a new export parameters object
            m_exportParams = new CmsExportParameters();
        } else {
            // reuse export parameters object stored in session
            m_exportParams = (CmsExportParameters)o;
        }

        if (CmsStringUtil.isEmpty(getParamAction()) && (m_exportParams.getResources().size() < 1)) {
            // on initial call, at least on resource input field has to be present
            List initialPaths = new ArrayList(1);
            initialPaths.add("/");
            m_exportParams.setResources(initialPaths);
        }
    }
174608
protected function _createHeapTable($sHeapTable, $sTableCharset)
    {
        $blDone = false;
        $oDB = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $sQ = "CREATE TABLE IF NOT EXISTS {$sHeapTable} ( `oxid` CHAR(32) NOT NULL default '' ) ENGINE=InnoDB {$sTableCharset}";
        if (($oDB->execute($sQ)) !== false) {
            $blDone = true;
            $oDB->execute("TRUNCATE TABLE {$sHeapTable}");
        }

        return $blDone;
    }
823545
public function copyArticle($sOldId = null, $sNewId = null, $sParentId = null)
    {
        $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();

        $sOldId = $sOldId ? $sOldId : $this->getEditObjectId();
        $sNewId = $sNewId ? $sNewId : \OxidEsales\Eshop\Core\Registry::getUtilsObject()->generateUID();

        $oArticle = oxNew(\OxidEsales\Eshop\Core\Model\BaseModel::class);
        $oArticle->init('oxarticles');
        if ($oArticle->load($sOldId)) {
            if ($myConfig->getConfigParam('blDisableDublArtOnCopy')) {
                $oArticle->oxarticles__oxactive->setValue(0);
                $oArticle->oxarticles__oxactivefrom->setValue(0);
                $oArticle->oxarticles__oxactiveto->setValue(0);
            }

            // setting parent id
            if ($sParentId) {
                $oArticle->oxarticles__oxparentid->setValue($sParentId);
            }

            // setting oxinsert/oxtimestamp
            $iNow = date('Y-m-d H:i:s', \OxidEsales\Eshop\Core\Registry::getUtilsDate()->getTime());
            $oArticle->oxarticles__oxinsert = new \OxidEsales\Eshop\Core\Field($iNow);

            // mantis#0001590: OXRATING and OXRATINGCNT not set to 0 when copying article
            $oArticle->oxarticles__oxrating = new \OxidEsales\Eshop\Core\Field(0);
            $oArticle->oxarticles__oxratingcnt = new \OxidEsales\Eshop\Core\Field(0);

            $oArticle->setId($sNewId);
            $oArticle->save();

            //copy categories
            $this->_copyCategories($sOldId, $sNewId);

            //atributes
            $this->_copyAttributes($sOldId, $sNewId);

            //sellist
            $this->_copySelectlists($sOldId, $sNewId);

            //crossseling
            $this->_copyCrossseling($sOldId, $sNewId);

            //accessoire
            $this->_copyAccessoires($sOldId, $sNewId);

            // #983A copying staffelpreis info
            $this->_copyStaffelpreis($sOldId, $sNewId);

            //copy article extends (longdescription)
            $this->_copyArtExtends($sOldId, $sNewId);

            //files
            $this->_copyFiles($sOldId, $sNewId);

            $this->resetContentCache();

            $myUtilsObject = \OxidEsales\Eshop\Core\Registry::getUtilsObject();
            $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();

            //copy variants
            $sQ = "select oxid from oxarticles where oxparentid = " . $oDb->quote($sOldId);
            $oRs = $oDb->select($sQ);
            if ($oRs !== false && $oRs->count() > 0) {
                while (!$oRs->EOF) {
                    $this->copyArticle($oRs->fields[0], $myUtilsObject->generateUid(), $sNewId);
                    $oRs->fetchRow();
                }
            }

            // only for top articles
            if (!$sParentId) {
                $this->setEditObjectId($oArticle->getId());

                //article number handling, warns for artnum duplicates
                $sFncParameter = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('fnc');
                $sArtNumField = 'oxarticles__oxartnum';
                if ($myConfig->getConfigParam('blWarnOnSameArtNums') &&
                    $oArticle->$sArtNumField->value && $sFncParameter == 'copyArticle'
                ) {
                    $sSelect = "select oxid from " . $oArticle->getCoreTableName() .
                               " where oxartnum = " . $oDb->quote($oArticle->$sArtNumField->value) .
                               " and oxid != " . $oDb->quote($sNewId);

                    if ($oArticle->assignRecord($sSelect)) {
                        $this->_aViewData["errorsavingatricle"] = 1;
                    }
                }
            }
        }
    }
504363
public function nextTick($iCnt)
    {
        $iExportedItems = $iCnt;
        $blContinue = false;
        if ($oArticle = $this->getOneArticle($iCnt, $blContinue)) {
            $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
            $oSmarty = \OxidEsales\Eshop\Core\Registry::getUtilsView()->getSmarty();
            $oSmarty->assign("sCustomHeader", \OxidEsales\Eshop\Core\Registry::getSession()->getVariable("sExportCustomHeader"));
            $oSmarty->assign("linenr", $iCnt);
            $oSmarty->assign("article", $oArticle);
            $oSmarty->assign("spr", $myConfig->getConfigParam('sCSVSign'));
            $oSmarty->assign("encl", $myConfig->getConfigParam('sGiCsvFieldEncloser'));
            $this->write($oSmarty->fetch("genexport.tpl", $this->getViewId()));

            return ++$iExportedItems;
        }

        return $blContinue;
    }
629871
private function getFieldOutputEnumSet($tblSrc, $fldType, $val, $iar = [])
    {
        $adnlThings = $this->establishDefaultEnumSet($fldType);
        if (array_key_exists('readonly', $val)) {
            return $this->getFieldOutputEnumSetReadOnly($val, $adnlThings);
        }
        $inAdtnl = $adnlThings['additional'];
        if ($iar !== []) {
            $inAdtnl = array_merge($inAdtnl, $iar);
        }
        $vlSlct    = explode(',', $this->getFieldValue($val));
        $slctOptns = $this->getSetOrEnum2Array($tblSrc, $val['COLUMN_NAME']);
        return $this->setArrayToSelect($slctOptns, $vlSlct, $val['COLUMN_NAME'] . $adnlThings['suffix'], $inAdtnl);
    }
38891
public function initialize(
        SessionInterface $session,
        ObjectTypeInterface $objectType,
        OperationContextInterface $context,
        ObjectDataInterface $objectData = null
    ) {
        if (count($this->getMissingBaseProperties($objectType->getPropertyDefinitions())) !== 0) {
            throw new CmisInvalidArgumentException(
                sprintf(
                    'Object type must have at least the base property definitions! '
                    . 'These property definitions are missing: %s',
                    implode(', ', PropertyIds::getBasePropertyKeys())
                )
            );
        };

        $this->session = $session;
        $this->objectType = $objectType;
        $this->secondaryTypes = null;
        $this->creationContext = clone $context;
        $this->refreshTimestamp = (integer) round(microtime(true) * 1000);

        if ($objectData !== null) {
            $this->initializeObjectData($objectData);
        }
    }
435440
private function _createContentTable(string $tableName)
    {
        $migration = new CreateSuperTableContentTable([
            'tableName' => $tableName
        ]);

        ob_start();
        $migration->up();
        ob_end_clean();
    }
498350
private function InitArchiveArticles()
    {
        $sql = Access::SqlBuilder();
        $tblArticle = Article::Schema()->Table();
        $tblCategory = Category::Schema()->Table();
        $join = $sql->Join($tblCategory);
        $joinCond = $sql->Equals($tblArticle->Field('Category'), $tblCategory->Field('ID'));
        $orderBy = $sql->OrderList($sql->OrderDesc($tblArticle->Field('Created')));
        $where = $this->PublishedCondition()->
                And_($sql->Equals($tblCategory->Field('Archive'), $sql->Value($this->archive->GetID())));
        $this->articles = Article::Schema()->Fetch(false, $where, $orderBy, null, 
                $this->ArticleOffset(), $this->ArticleCount(), $join, Sql\JoinType::Inner(), $joinCond);
        $this->articlesTotal = Article::Schema()->Count(false, $where, null, $join, Sql\JoinType::Inner(), $joinCond);
    }
841289
function _saveHeader($iSBDcnt, $iBBcnt, $iPPScnt)
    {
        $FILE = $this->_FILEH_;
  
        // Calculate Basic Setting
        $iBlCnt = $this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE;
        $i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / OLE_LONG_INT_SIZE;
  
        $iBdExL = 0;
        $iAll = $iBBcnt + $iPPScnt + $iSBDcnt;
        $iAllW = $iAll;
        $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
        $iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
  
        // Calculate BD count
        if ($iBdCnt > $i1stBdL) {
            while (1) {
                $iBdExL++;
                $iAllW++;
                $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
                $iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
                if ($iBdCnt <= ($iBdExL*$iBlCnt+ $i1stBdL)) {
                    break;
                }
            }
        }
  
        // Save Header
        fwrite($FILE,
                  "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
                  . "\x00\x00\x00\x00"
                  . "\x00\x00\x00\x00"
                  . "\x00\x00\x00\x00"
                  . "\x00\x00\x00\x00"
                  . pack("v", 0x3b)
                  . pack("v", 0x03)
                  . pack("v", -2)
                  . pack("v", 9)
                  . pack("v", 6)
                  . pack("v", 0)
                  . "\x00\x00\x00\x00"
                  . "\x00\x00\x00\x00"
                  . pack("V", $iBdCnt) 
                  . pack("V", $iBBcnt+$iSBDcnt) //ROOT START
                  . pack("V", 0)
                  . pack("V", 0x1000)
                  . pack("V", 0)                  //Small Block Depot
                  . pack("V", 1)
          );
        // Extra BDList Start, Count
        if ($iBdCnt < $i1stBdL) {
            fwrite($FILE,
                      pack("V", -2).      // Extra BDList Start
                      pack("V", 0)        // Extra BDList Count
                  );
        } else {
            fwrite($FILE, pack("V", $iAll+$iBdCnt) . pack("V", $iBdExL));
        }

        // BDList
        for ($i = 0; $i < $i1stBdL && $i < $iBdCnt; $i++) {
            fwrite($FILE, pack("V", $iAll+$i));
        }
        if ($i < $i1stBdL) {
            for ($j = 0; $j < ($i1stBdL-$i); $j++) {
                fwrite($FILE, (pack("V", -1)));
            }
        }
    }
303750
public function beginTransaction(
        $withConsistentSnapshot = false,
        $readOnly = false,
        FileInterface $transactionStorage = null
    ) {
        /* @var $file FileInterface */
        $file = $this->file;

        if (is_null($transactionStorage)) {
            $transactionStorage = new FileResourceProxy(fopen("php://memory", "w"));
        }

        if (count($this->transactionStorageStack) <= 0) {
            $this->fileSeekBeforeTransaction = $file->tell();
            $this->seekPositionStack[] = $file->tell();
            $this->fileSizeStack[] = $file->getLength();

            $file->lock(LOCK_EX);

        } else {
            $this->seekPositionStack[] = end($this->seekPositionStack);
            $this->fileSizeStack[] = end($this->fileSizeStack);
        }

        $this->transactionStorageStack[] = $transactionStorage;
        $this->pageMapStack[] = array();

        $transactionStorage->truncate(0);

        if ($this->isLocked) {
            $transactionStorage->lock(LOCK_EX);
        }
    }
240438
function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
    {
        if ( $currentVersion != false )
        {
            $idString = $originalContentObjectAttribute->attribute( "data_text" );
            $contentObjectAttribute->setAttribute( "data_text", $idString );
            $contentObjectAttribute->store();
        }
    }
552461
public static function GetInstanceDataFromSession($sListSessionKey)
    {
        if (!array_key_exists(TdbShopArticleList::SESSIN_DUMP_NAME, $_SESSION)) {
            $_SESSION[TdbShopArticleList::SESSIN_DUMP_NAME] = array();
        }
        $aList = null;
        if (array_key_exists($sListSessionKey, $_SESSION[TdbShopArticleList::SESSIN_DUMP_NAME])) {
            $aList = $_SESSION[TdbShopArticleList::SESSIN_DUMP_NAME][$sListSessionKey];
        }

        return $aList;
    }
1331957
function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
    {
        if ( $currentVersion != false )
        {
            $xmlText = eZXMLTextType::rawXMLText( $originalContentObjectAttribute );
            $contentObjectAttribute->setAttribute( "data_text", $xmlText );
        }
        else
        {
            $parser = new eZXMLInputParser();
            $doc = $parser->createRootNode();
            $xmlText = eZXMLTextType::domString( $doc );
            $contentObjectAttribute->setAttribute( "data_text", $xmlText );
        }
    }
429877
static function initialize( $context, $locale, $filename, $useCache = true )
    {
        $instance = false;
        $file = $locale . '/' . $filename;
        if ( !empty( $GLOBALS['eZTSTranslationTables'][$file] ) )
        {
            $instance = $GLOBALS['eZTSTranslationTables'][$file];
            if ( $instance->hasInitializedContext( $context ) )
            {
                return $instance;
            }
        }

        eZDebug::createAccumulatorGroup( 'tstranslator', 'TS translator' );
        eZDebug::accumulatorStart( 'tstranslator_init', 'tstranslator', 'TS init' );
        if ( !$instance )
        {
            $instance = new eZTSTranslator( $locale, $filename, $useCache );
            $GLOBALS['eZTSTranslationTables'][$file] = $instance;
            $manager = eZTranslatorManager::instance();
            $manager->registerHandler( $instance );
        }
        $instance->load( $context );
        eZDebug::accumulatorStop( 'tstranslator_init' );
        return $instance;
    }