Location: PHPKode > projects > PhpBlock > A9.8/script/tick/removeoldimage.php
<?php
include_once $PATH_TO_CODE."/script/tick/allincludefortick.php";
class RemoveOldImageTick extends Tick {
    public function getName() {
        return "Image generation";
    }
    public function run() {

        global $gloObjectManager;

        $locBlockImageToGenerate = 50;
        $locZoneImageToGenerate = 250;

        //executer("LOCK TABLES block WRITE, zone WRITE", true);
        $resZone = executer("SELECT zoneId FROM zone WHERE modified=1 ORDER BY z ASC, blockId LIMIT  $locZoneImageToGenerate");
        if(mysql_affected_rows() > 0) {
        	executer("UPDATE zone SET modified=0 WHERE modified=1 ORDER BY z ASC, blockId LIMIT $locZoneImageToGenerate");
        }

        $resBlock = executer("SELECT blockId FROM block WHERE modified=1 ORDER BY z ASC, blockId LIMIT $locBlockImageToGenerate");
        if(mysql_affected_rows() > 0) {
        	executer("UPDATE block SET modified=0 WHERE modified=1 ORDER BY z ASC, blockId LIMIT $locBlockImageToGenerate");
        }
        //executer("COMMIT");
        //executer("UNLOCK TABLES", true);

        Log::debug("removeoldimage.php generate all image zone");
        $locListBlockId = array();
        while($row = mysql_fetch_array($resZone)) {
            $locZoneId = $row[0];
            $locZone = $gloObjectManager->getZone($locZoneId);
            $locZone->createImage(Constante::$ZONE_IMAGE_SIZE);
            Log::info("create zone image $locZoneId");
            $locBlockId=$locZone->blockId;
            if(!in_array($locBlockId, $locListBlockId)) {
                array_push($locListBlockId, $locBlockId);
            }
        }

        Log::debug("removeoldimage.php get all block");
        while($row = mysql_fetch_array($resBlock)) {
            $locBlockId = $row[0];
            if(!in_array($locBlockId, $locListBlockId)) {
                array_push($locListBlockId, $locBlockId);
            }
        }

        Log::debug("removeoldimage.php generate all image block");
        foreach($locListBlockId as $locBlockId) {
            $locBlock = $gloObjectManager->getBlock($locBlockId);
            $locBlock->createImage(Constante::$BLOCK_IMAGE_SIZE);
            Log::info("create block image $locBlockId");
        }

        if(count($locListBlockId) > 0) {
            $locListBlockIdWhereClause = implode(",", $locListBlockId);
            executer("UPDATE block SET modifierImageCount=modifierImageCount+1, timestamp=".time()." WHERE blockId IN ($locListBlockIdWhereClause)");
        }
    }
}
?>
Return current item: PhpBlock