47 $archiveName = $importableRevision->getArchiveName();
48 $localRepo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
50 $this->logger->debug( __METHOD__ .
": Importing archived file as $archiveName" );
51 $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
52 $localRepo, $archiveName );
54 $file = $localRepo->newFile( $importableRevision->getTitle() );
55 $file->load( IDBAccessObject::READ_LATEST );
56 $this->logger->debug( __METHOD__ .
': Importing new file as ' . $file->getName() );
57 if ( $file->exists() && $file->getTimestamp() > $importableRevision->getTimestamp() ) {
58 $archiveName = $importableRevision->getTimestamp() .
'!' . $file->getName();
59 $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
60 $localRepo, $archiveName );
61 $this->logger->debug( __METHOD__ .
": File already exists; importing as $archiveName" );
65 $this->logger->debug( __METHOD__ .
': Bad file for ' . $importableRevision->getTitle() );
66 return $this->newNotOkStatus();
69 # Get the file source or download if necessary
70 $source = $importableRevision->getFileSrc();
71 $autoDeleteSource = $importableRevision->isTempSrc();
74 $autoDeleteSource =
true;
77 $this->logger->debug( __METHOD__ .
": Could not fetch remote file." );
78 return $this->newNotOkStatus();
82 if ( $autoDeleteSource ) {
83 $tmpFile->autocollect();
86 $sha1File = ltrim( sha1_file(
$source ),
'0' );
87 $sha1 = $importableRevision->getSha1();
88 if ( $sha1 && ( $sha1 !== $sha1File ) ) {
89 $this->logger->debug( __METHOD__ .
": Corrupt file $source." );
90 return $this->newNotOkStatus();
93 $user = $importableRevision->getUserObj()
94 ?: User::newFromName( $importableRevision->getUser(),
false );
96 # Do the actual upload
98 $status = $file->uploadOld(
100 $importableRevision->getTimestamp(),
101 $importableRevision->getComment(),
106 $status = $file->upload(
108 $importableRevision->getComment(),
109 $importableRevision->getComment(),
112 $importableRevision->getTimestamp(),
115 $this->shouldCreateNullRevision
119 if ( $status->isGood() ) {
120 $this->logger->debug( __METHOD__ .
": Successful" );
122 $this->logger->debug( __METHOD__ .
': failed: ' . $status->getHTML() );