Ejemplo n.º 1
0
 /**
  * @see	\wcf\system\event\IEventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     // delete obsolete file uploads
     // files are considered obsolete when they are not assigned to
     // at least one category and are older than one day
     $sql = "SELECT\t\tfile.fileID\n\t\t\tFROM\t\tcms" . WCF_N . "_file file\n\t\t\tLEFT JOIN\tcms" . WCF_N . "_file_to_category file_to_category ON (file.fileID = file_to_category.fileID)\n\t\t\tWHERE\t\tfile_to_category.categoryID IS NULL\n\t\t\t\t\tAND\tfile.uploadTime < ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array(TIME_NOW - 86400));
     $fileIDs = array();
     while ($row = $statement->fetchArray()) {
         $fileIDs[] = $row['fileID'];
     }
     $fileAction = new FileAction($fileIDs, 'delete');
     $fileAction->executeAction();
     // delete outdated revisions
     if (CMS_REVISION_DELETE) {
         // page revisions
         $sql = "DELETE FROM\tcms" . WCF_N . "_page_revision\n\t\t\t\tWHERE\t\ttime < ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array(TIME_NOW - CMS_REVISION_DELETE * 86400));
     }
 }
Ejemplo n.º 2
0
$returnValues = $objectAction->getReturnValues();
$categoryID = $returnValues['returnValues']->categoryID;
//get old news images
$list = new NewsImageList();
$list->readObjects();
$oldIDs = array();
foreach ($list->getObjects() as $image) {
    //get file hash
    $fileHash = sha1_file(CMS_DIR . 'images/news/' . $image->filename);
    $folder = substr($fileHash, 0, 2);
    //get size
    $size = filesize(CMS_DIR . 'images/news/' . $image->filename);
    //mime type
    $mime = FileUtil::getMimeType(CMS_DIR . 'images/news/' . $image->filename);
    //create db entry
    $action = new FileAction(array(), 'create', array('data' => array('title' => $image->getTitle(), 'filesize' => $size, 'fileType' => $mime, 'fileHash' => $fileHash, 'uploadTime' => TIME_NOW)));
    $action->executeAction();
    $returnValues = $action->getReturnValues();
    //set old IDs
    $oldIDs[$image->imageID] = $returnValues['returnValues']->fileID;
    if (!is_dir(CMS_DIR . 'files/' . $folder)) {
        FileUtil::makePath(CMS_DIR . 'files/' . $folder);
    }
    copy(CMS_DIR . 'images/news/' . $image->filename, CMS_DIR . 'files/' . $folder . '/' . $returnValues['returnValues']->fileID . '-' . $fileHash);
    @unlink(CMS_DIR . 'images/news/' . $image->filename);
    //insert into news image category
    $sql = "INSERT INTO cms" . WCF_N . "_file_to_category VALUES (?, ?)";
    $statement = WCF::getDB()->prepareStatement($sql);
    $statement->execute(array($returnValues['returnValues']->fileID, $categoryID));
}
//loop through news