79 lines
2.0 KiB
PHP
79 lines
2.0 KiB
PHP
<?php
|
|
|
|
class stProductOptionsFix
|
|
{
|
|
protected static $dbm = null;
|
|
|
|
public function executeUpdate($offset)
|
|
{
|
|
self::initDatabase();
|
|
|
|
$offset = self::execute($offset);
|
|
|
|
self::shutdownDatabase();
|
|
|
|
return $offset;
|
|
}
|
|
|
|
public function execute($offset)
|
|
{
|
|
$c = new Criteria();
|
|
|
|
$c->addSelectColumn(ProductPeer::ID);
|
|
|
|
$c->setLimit(50);
|
|
|
|
$c->setOffset($offset);
|
|
|
|
$rs = ProductPeer::doSelectRs($c);
|
|
|
|
$ids = array();
|
|
|
|
while($rs->next())
|
|
{
|
|
$id = $rs->getInt(1);
|
|
|
|
$ids[] = $id;
|
|
|
|
$ps = Propel::getConnection()->prepareStatement(sprintf('UPDATE %s, %s SET %s = %s WHERE %s = %s AND %s = ?',
|
|
ProductOptionsValuePeer::TABLE_NAME,
|
|
ProductOptionsFieldPeer::TABLE_NAME,
|
|
ProductOptionsValuePeer::OPT_FILTER_ID,
|
|
ProductOptionsFieldPeer::PRODUCT_OPTIONS_FILTER_ID,
|
|
ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID,
|
|
ProductOptionsFieldPeer::ID,
|
|
ProductOptionsValuePeer::PRODUCT_ID
|
|
));
|
|
|
|
$ps->setInt(1, $id);
|
|
$ps->executeUpdate();
|
|
|
|
ProductOptionsValuePeer::updateProductColor($id);
|
|
}
|
|
|
|
$con = Propel::getConnection();
|
|
$con->executeQuery(sprintf("UPDATE st_product_options_value v LEFT JOIN st_product_options_value c ON c.LFT BETWEEN v.LFT AND v.RGT AND c.product_id = v.product_id AND c.RGT - c.LFT = 1 AND c.stock > 0 SET v.stock = IFNULL(c.stock, 0) WHERE v.product_id IN (%s)",
|
|
implode(',', $ids)));
|
|
|
|
usleep(500000);
|
|
|
|
return $offset + count($ids);
|
|
}
|
|
|
|
public static function count()
|
|
{
|
|
return ProductPeer::doCount(new Criteria());
|
|
}
|
|
|
|
public static function initDatabase()
|
|
{
|
|
self::$dbm = new sfDatabaseManager();
|
|
|
|
self::$dbm->initialize();
|
|
}
|
|
|
|
public static function shutdownDatabase()
|
|
{
|
|
self::$dbm->shutdown();
|
|
}
|
|
} |