Skip to content

Instantly share code, notes, and snippets.

@sthamann
Created February 2, 2015 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sthamann/4ed937a0fd2aaf791001 to your computer and use it in GitHub Desktop.
Save sthamann/4ed937a0fd2aaf791001 to your computer and use it in GitHub Desktop.
<?php
/**
* Shopware 4
* Copyright © shopware AG
*
* According to our dual licensing model, this program can be used either
* under the terms of the GNU Affero General Public License, version 3,
* or under a proprietary license.
*
* The texts of the GNU Affero General Public License with an additional
* permission and of our proprietary license can be found at and
* in the LICENSE file you have received along with this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* "Shopware" is a registered trademark of shopware AG.
* The licensing of the program under the AGPLv3 does not imply a
* trademark license. Therefore any rights, title and interest in
* our trademarks remain entirely with us.
*/
/**
* @category Shopware
* @package Shopware\Controllers\Frontend
* @copyright Copyright (c) shopware AG (http://www.shopware.de)
*/
class Shopware_Controllers_Frontend_Import extends Enlight_Controller_Action
{
public function indexAction()
{
$localpath = dirname(__FILE__)."/../../../../files/downloads/";
$remotePath = "http://www.eservice-online.de/out/media/";
/** @var \Enlight_Components_Db_Adapter_Pdo_Mysql $db */
$db = \Enlight_Components_Db::factory("pdo_mysql", array(
'username' => '',
'password' => '',
'dbname' => '',
'host' => '',
'charset' => 'utf8',
'adapter' => 'pdo_mysql'
));
$getDocuments = $db->fetchAll("
SELECT oxmediaurls.*,oxarticles.OXARTNUM,oxarticles.oxtitle FROM `oxmediaurls`,oxarticles WHERE OXOBJECTID = oxarticles.OXID
ORDER BY oxarticles.OXARTNUM ASC
");
Shopware()->Db()->query("
DELETE FROM s_articles_downloads
");
foreach ($getDocuments as $document){
$ordernumber = $document["OXARTNUM"];
$description = $document["OXDESC"];
$path = $document["OXURL"];
// Clear-Path
$path = basename($path);
$path = str_replace(" ","%20",$path);
$documentUrl = $remotePath.$path;
$document = file_get_contents($documentUrl);
if(strlen($document)==0){
echo "<p style='color:#F00'>|- Artikel: $ordernumber, Datei: $documentUrl 404 Error</p><br />";
continue;
}
file_put_contents($localpath . str_replace("%20"," ",$path), $document);
// Write entry to database
$getShopwareArticleId = Shopware()->Db()->fetchOne("SELECT articleID FROM s_articles_details WHERE
ordernumber = ?
",array($ordernumber));
if (empty($getShopwareArticleId)){
echo "<p style='color:#F00'>|- Artikel: $ordernumber nicht in Shopware Zieldatenbank gefunden. Artikel veraltet?</p><br />";
echo "|- $ordernumber NOT FOUND <br />";
continue;
}
// Add entry to s_articles_downloads
Shopware()->Db()->query("
INSERT INTO s_articles_downloads (articleID,description,filename,size)
VALUES (
?,?,?,?
)
",array($getShopwareArticleId,$description,"/files/downloads/".$path,filesize($localpath.$path)));
echo "<p style='color:#002070'>|- Artikel: $ordernumber, Datei: $documentUrl Import Successful</p><br />";
}
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment