public function process($prefix, $fieldName) { $this->pipe->process($fieldName); $this->errors = $this->pipe->getErrors(); if (sizeof($this->errors) > 0) { //set errors and return return; } //get meta data and actual file data $this->mediaData = $this->pipe->getMediaData(); $sBlobData = $this->pipe->getFileData(); if (is_null($sBlobData)) { trigger_error('File processing returned Null Data', E_USER_ERROR); } // @todo - check mime type of an image here? // the downside : valid files without mime type would be rejected // image upload is done // clean original file name of malformed utf-8 chars $cleanName = Util::filterBadUtf8($this->mediaData->originalName); if (empty($cleanName)) { trigger_error("image name consists solely of malformed utf-8", E_USER_ERROR); } $this->mediaData->originalName = $cleanName; // now do image specific processings // and create a thumbnail $tBlobData = $this->computeHW($sBlobData); //amazon s3 meta headers $offset = 3600 * 24 * 365; $expiresOn = gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $offset); $headers = array(); $headers["Expires"] = $expiresOn; $headers["Cache-Control"] = "public, max-age=31536000"; $headers["Content-Type"] = $this->mediaData->mime; $storeName = $this->store->persist($prefix, $this->mediaData->originalName, $sBlobData, $headers); // override content-type header for thumbnail // all thumbnails are image type jpeg $headers["Content-Type"] = "image/jpeg"; //change name to jpeg for thumbnail $tname = Util::getThumbnailName($this->mediaData->originalName); $thumbnail = $this->store->persist($prefix, $tname, $tBlobData, $headers); if (is_null($storeName)) { array_push($this->errors, "file storage failed"); return; } $this->mediaData->storeName = $storeName; $this->mediaData->thumbnail = $thumbnail; $this->mediaData->thumbnailName = $tname; if ($this->isS3Store) { $this->mediaData->store = 's3'; $this->mediaData->bucket = Config::getInstance()->get_value("aws.bucket"); } else { $this->mediaData->store = 'local'; //relative URL for local uploads $this->mediaData->bucket = 'media'; } }
$mysqli = MySQL\Connection::getInstance()->getHandle(); $start = $count * 50 + 1; $end = $start + 49; printf("processing rows between %d and %d \n", $start, $end); $sql = " select id,images_json from sc_post where (id <= {end}) and (id >= {start} ) "; $sql = str_replace(array("{end}", "{start}"), array(0 => $end, 1 => $start), $sql); $rows = MySQL\Helper::fetchRows($mysqli, $sql); foreach ($rows as $row) { //remove malformed utf-8 characters $fjson = iconv('UTF-8', 'UTF-8//IGNORE', $row['images_json']); $images = json_decode($fjson); //printf("code from json_decode is %d \n",json_last_error()); $data = array(); if (!empty($images)) { foreach ($images as $image) { $image->thumbnailName = Util::getThumbnailName($image->originalName); //printf("tname is %s \n",$image->thumbnailName); array_push($data, $image); //update sc_media.thumbnail_name updateMedia($mysqli, $image->id, $image->thumbnailName); } //new mediaVO $strMediaVO = json_encode($data); //push new mediaVO to sc_post updatePost($mysqli, $row['id'], $strMediaVO); } else { //no images case $strMediaVO = '[]'; updatePost($mysqli, $row['id'], $strMediaVO); } }
$row = MySQL\Helper::fetchRow($mysqli, $sql); $total = $row["total"]; $pageSize = 50; $pages = ceil($total / $pageSize); $count = 0; while ($count <= $pages) { $start = $count * $pageSize + 1; $end = $start + ($pageSize - 1); $sql = " select * from sc_media where (id <= {end}) and (id >= {start} ) "; $sql = str_replace(array("{end}", "{start}"), array(0 => $end, 1 => $start), $sql); $rows = MySQL\Helper::fetchRows($mysqli, $sql); printf("processing row between %d and %d \n", $start, $end); foreach ($rows as $row) { $rowId = $row["id"]; $name = $row["original_name"]; $tname = \com\indigloo\Util::getThumbnailName($name); if (empty($tname)) { $message = sprintf("Bad thumbnail name at id %d \n", $rowId); trigger_error($message, E_USER_ERROR); } //guess mime type $mime = \com\indigloo\Util::getMimeFromName($name); if (empty($mime)) { //report it printf("Bad mime type for media id %d \n", $rowId); $mime = "application/octet-stream"; } // update sc_media row updateMediaMime($mysqli, $rowId, $tname, $mime); } sleep(1);