49 $archiveName = $importableRevision->getArchiveName();
50 $localRepo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
52 $this->logger->debug( __METHOD__ .
": Importing archived file as $archiveName" );
53 $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
54 $localRepo, $archiveName );
56 $file = $localRepo->newFile( $importableRevision->getTitle() );
57 $file->load( IDBAccessObject::READ_LATEST );
58 $this->logger->debug( __METHOD__ .
': Importing new file as ' . $file->getName() );
59 if ( $file->exists() && $file->getTimestamp() > $importableRevision->getTimestamp() ) {
60 $archiveName = $importableRevision->getTimestamp() .
'!' . $file->getName();
61 $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
62 $localRepo, $archiveName );
63 $this->logger->debug( __METHOD__ .
": File already exists; importing as $archiveName" );
67 $this->logger->debug( __METHOD__ .
': Bad file for ' . $importableRevision->getTitle() );
68 return $this->newNotOkStatus();
71 # Get the file source or download if necessary
72 $source = $importableRevision->getFileSrc();
73 $autoDeleteSource = $importableRevision->isTempSrc();
75 $source = $this->downloadSource( $importableRevision );
76 $autoDeleteSource =
true;
79 $this->logger->debug( __METHOD__ .
": Could not fetch remote file." );
80 return $this->newNotOkStatus();
84 if ( $autoDeleteSource ) {
85 $tmpFile->autocollect();
88 $sha1File = ltrim( sha1_file(
$source ),
'0' );
89 $sha1 = $importableRevision->getSha1();
90 if ( $sha1 && ( $sha1 !== $sha1File ) ) {
91 $this->logger->debug( __METHOD__ .
": Corrupt file $source." );
92 return $this->newNotOkStatus();
95 $user = $importableRevision->getUserObj()
96 ?: User::newFromName( $importableRevision->getUser(),
false );
98 # Do the actual upload
100 $status = $file->uploadOld(
102 $importableRevision->getTimestamp(),
103 $importableRevision->getComment(),
108 $status = $file->upload(
110 $importableRevision->getComment(),
111 $importableRevision->getComment(),
114 $importableRevision->getTimestamp(),
117 $this->shouldCreateNullRevision
121 if ( $status->isGood() ) {
122 $this->logger->debug( __METHOD__ .
": Successful" );
124 $this->logger->debug( __METHOD__ .
': failed: ' . $status->getHTML() );