Example #1
0
 public function checkConverted($key, $format, $fileType = "", $contentType = "")
 {
     global $awsS3Bucket;
     if ($fileType == "" or $contentType == "") {
         // update status in the DB
         $db = getDBObject();
         $formatInfo = $db->getFormat($format);
         $fileType = $formatInfo["file_type"];
         $contentType = $formatInfo["content_type"];
     }
     // check existance
     $s3 = getS3Object();
     $pdfName = getStorageName($key, $format, ".pdf");
     if ($contentType == "application/zip") {
         $convName = getStorageName($key, $format, ".zip");
     } else {
         $convName = getStorageName($key, $format, ".{$fileType}");
     }
     $logName = getStorageName($key, $format, ".txt");
     // PDFs can be found only for books that where added through early versions of fb2pdf,
     // when there was no support for formats. There is no need to query them
     // if format is set to semething other then 1.
     $pdfExists = $format == 1 && $s3->objectExists($awsS3Bucket, $pdfName);
     $convExists = $s3->objectExists($awsS3Bucket, $convName);
     $logExists = $s3->objectExists($awsS3Bucket, $logName);
     // check status and generate links
     $status = self::STATUS_PROGRESS;
     if (($pdfExists or $convExists) and $logExists) {
         $status = self::STATUS_SUCCESS;
         $this->convFile = $pdfExists ? "getfile.php?key={$pdfName}" : "getfile.php?key={$convName}";
         $this->logFile = "getfile.php?key={$logName}";
     } else {
         if ($logExists) {
             $status = self::STATUS_ERROR;
             $this->logFile = "getfile.php?key={$logName}";
         }
     }
     return $status;
 }
<?php

require_once 'exemplo_interface.php';
function getDBObject($dbType = 'mysql')
{
    switch ($dbType) {
        case 'postgres':
            return new PostgresDB();
        case 'oracle':
            return new OracleDB();
        default:
            return new MySQLDB();
    }
}
$db = getDBObject();
// Tenho certeza que o objeto retornado implementa a interface iDB
// Isso garante que o objeto terá os métodos setConnData(), connect() e
// readDataFromTable() exatamente da forma como descrito na interface
if ($db instanceof iDB) {
    /* Independente do banco utilizado, o trecho abaixo sempre vai funcionar */
    $db->setConnData('localhost', 'admin', 'p4pm6');
    $db->connect();
    $usuarios = $db->readDataFromTable('usuario');
}
Example #3
0
 private function requestConvert($format)
 {
     global $awsS3Bucket, $secret;
     // send SQS message
     $callbackUrl = getFullUrl("conv_callback.php");
     $db = getDBObject();
     $formatInfo = $db->getFormat($format);
     $formatParams = $db->getFormatParameters($format);
     $fileType = $formatInfo["file_type"];
     $contentType = $formatInfo["content_type"];
     if (!sqsPutMessage($this->bookKey, "http://s3.amazonaws.com/{$awsS3Bucket}/{$this->bookKey}.fb2", $this->fileName, $callbackUrl, md5($secret . $this->bookKey), $this->email, $format, $formatParams, $fileType, $contentType)) {
         throw new Exception("Unable to send Amazon SQS message for key {$this->bookKey}.", self::ERR_CONVERT);
     }
 }