60 $archiveName = $importableRevision->getArchiveName();
61 $localRepo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
63 $this->logger->debug( __METHOD__ .
": Importing archived file as $archiveName" );
65 $localRepo, $archiveName );
67 $file = $localRepo->newFile( $importableRevision->getTitle() );
68 $file->load( File::READ_LATEST );
69 $this->logger->debug( __METHOD__ .
': Importing new file as ' .
$file->getName() );
70 if (
$file->exists() &&
$file->getTimestamp() > $importableRevision->getTimestamp() ) {
71 $archiveName = $importableRevision->getTimestamp() .
'!' .
$file->getName();
73 $localRepo, $archiveName );
74 $this->logger->debug( __METHOD__ .
": File already exists; importing as $archiveName" );
78 $this->logger->debug( __METHOD__ .
': Bad file for ' . $importableRevision->getTitle() );
82 # Get the file source or download if necessary
83 $source = $importableRevision->getFileSrc();
84 $autoDeleteSource = $importableRevision->isTempSrc();
87 $autoDeleteSource =
true;
90 $this->logger->debug( __METHOD__ .
": Could not fetch remote file." );
95 if ( $autoDeleteSource ) {
96 $tmpFile->autocollect();
99 $sha1File = ltrim( sha1_file(
$source ),
'0' );
100 $sha1 = $importableRevision->getSha1();
101 if ( $sha1 && ( $sha1 !== $sha1File ) ) {
102 $this->logger->debug( __METHOD__ .
": Corrupt file $source." );
106 $user = $importableRevision->getUserObj()
109 # Do the actual upload
111 $status =
$file->uploadOld(
113 $importableRevision->getTimestamp(),
114 $importableRevision->getComment(),
119 $status =
$file->upload(
121 $importableRevision->getComment(),
122 $importableRevision->getComment(),
125 $importableRevision->getTimestamp(),
128 $this->shouldCreateNullRevision
132 if ( $status->isGood() ) {
133 $this->logger->debug( __METHOD__ .
": Successful" );
135 $this->logger->debug( __METHOD__ .
': failed: ' . $status->getHTML() );