dongyuying1507 2015-07-29 06:30
浏览 58
已采纳

运行PHP脚本不起作用

I have a php script for my magento page which fixes texterrors. It worked fine when I had like 10 products in my shop. Now I do have over 3000 and if I try to run the script, it takes about 3 seconds and then an empty page is shown.

<?php
include_once "app/Mage.php";
Mage::init();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$yourstring = array( 'ä', 'ö' , 'Ã' , 'ü' , '°' , '<short_description>' , '</short_description>    <full_description>' , '</full_description>' , '</weight>');
$newstring =  array( 'ä' , 'ö'  , 'ø'    , 'ü'  , '°'  , 'SHORT_DESCRIPTION'   , 'SHORT_DESCRIPTION'                          , 'DELETE'              , 'DELETE');

$_productCollection = Mage::getModel('catalog/product')
                    ->getCollection()
                    ->addAttributeToSelect('*')
                    ->load();

echo 'RUNNING SCRIPT...<br /><br /><br /><br />';               
for ($i = 0; $i <= 8; $i++) {
  echo 'Letter to fix: '.$newstring[$i].'<br />';
  foreach($_productCollection as $_product) {

    if (strpos($_product->getDescription(),$yourstring[$i]) !== false) {

      $newdescription = str_replace($yourstring[$i],$newstring[$i],$_product->getDescription());
      $_product->setDescription($newdescription);
      $_product->save();

      echo 'Updated product: '.$_product->getName().'<br />';
    }

  }
  echo '<br /><br />';
}
?>

It should at least display the "RUNNING SCRIPT" message but it doesn't. I'm really confused.

Thank you!

  • 写回答

1条回答 默认 最新

  • dongzhiyong8577 2015-07-29 07:36
    关注

    At the beginning of the script (right before include) add error_reporting(E_ALL ^ E_NOTICE);. Thanks to that errors will be visible at the screen and you will be able to correct them.

    If there is no errors and script will still behave as you described try change allowed execution time. For more information look here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?