59 $archiveName = $importableRevision->getArchiveName();
60 $localRepo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
62 $this->logger->debug( __METHOD__ .
"Importing archived file as $archiveName" );
64 $localRepo, $archiveName );
66 $file = $localRepo->newFile( $importableRevision->getTitle() );
67 $file->load( File::READ_LATEST );
68 $this->logger->debug( __METHOD__ .
'Importing new file as ' .
$file->getName() );
69 if (
$file->exists() &&
$file->getTimestamp() > $importableRevision->getTimestamp() ) {
70 $archiveName = $importableRevision->getTimestamp() .
'!' .
$file->getName();
72 $localRepo, $archiveName );
73 $this->logger->debug( __METHOD__ .
"File already exists; importing as $archiveName" );
77 $this->logger->debug( __METHOD__ .
': Bad file for ' . $importableRevision->getTitle() );
81 # Get the file source or download if necessary
82 $source = $importableRevision->getFileSrc();
83 $autoDeleteSource = $importableRevision->isTempSrc();
86 $autoDeleteSource =
true;
89 $this->logger->debug( __METHOD__ .
": Could not fetch remote file." );
94 if ( $autoDeleteSource ) {
95 $tmpFile->autocollect();
98 $sha1File = ltrim( sha1_file(
$source ),
'0' );
99 $sha1 = $importableRevision->getSha1();
100 if ( $sha1 && ( $sha1 !== $sha1File ) ) {
101 $this->logger->debug( __METHOD__ .
": Corrupt file $source." );
105 $user = $importableRevision->getUserObj()
108 # Do the actual upload
110 $status =
$file->uploadOld(
112 $importableRevision->getTimestamp(),
113 $importableRevision->getComment(),
118 $status =
$file->upload(
120 $importableRevision->getComment(),
121 $importableRevision->getComment(),
124 $importableRevision->getTimestamp(),
127 $this->shouldCreateNullRevision
131 if ( $status->isGood() ) {
132 $this->logger->debug( __METHOD__ .
": Successful" );
134 $this->logger->debug( __METHOD__ .
': failed: ' . $status->getHTML() );