瀏覽代碼

Update FixUsernames command, fixes remote username search

Daniel Supernault 5 年之前
父節點
當前提交
0f943f672c
共有 1 個文件被更改,包括 41 次插入1 次删除
  1. 41 1
      app/Console/Commands/FixUsernames.php

+ 41 - 1
app/Console/Commands/FixUsernames.php

@@ -40,8 +40,14 @@ class FixUsernames extends Command
      */
      */
     public function handle()
     public function handle()
     {
     {
+        $this->line(' ');
         $this->info('Collecting data ...');
         $this->info('Collecting data ...');
+        $this->line(' ');
+        $this->restrictedCheck();
+    }
 
 
+    protected function restrictedCheck()
+    {
         $affected = collect([]);
         $affected = collect([]);
 
 
         $restricted = RestrictedNames::get();
         $restricted = RestrictedNames::get();
@@ -61,6 +67,7 @@ class FixUsernames extends Command
                 }
                 }
             }
             }
         });
         });
+        
         if($affected->count() > 0) {
         if($affected->count() > 0) {
             $this->info('Found: ' . $affected->count() . ' affected usernames');
             $this->info('Found: ' . $affected->count() . ' affected usernames');
 
 
@@ -118,7 +125,40 @@ class FixUsernames extends Command
 
 
             $this->info('Fixed ' . $affected->count() . ' usernames!');
             $this->info('Fixed ' . $affected->count() . ' usernames!');
         } else {
         } else {
-            $this->info('No affected usernames found!');
+            $this->info('No restricted usernames found!');
         }
         }
+        $this->line(' ');
+        $this->versionZeroTenNineFix();
+    }
+
+    protected function versionZeroTenNineFix()
+    {
+        $profiles = Profile::whereNotNull('domain')
+            ->whereNull('private_key')
+            ->where('username', 'not like', '@%@%')
+            ->get();
+
+        $count = $profiles->count();
+
+        if($count > 0) {
+            $this->info("Found {$count} remote usernames to fix ...");
+            $this->line(' ');
+        } else {
+            $this->info('No remote fixes found!');
+            $this->line(' ');
+            return;
+        }
+        foreach($profiles as $p) {
+            $this->info("Fixed $p->username => $p->webfinger");
+            $p->username = $p->webfinger ?? "@{$p->username}@{$p->domain}";
+            if(Profile::whereUsername($p->username)->exists()) {
+                return;
+            }
+            $p->save();
+        }
+        if($count > 0) {
+            $this->line(' ');
+        }
+
     }
     }
 }
 }