]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/editapplication.php
Merge branch '0.9.x' into activityexport
[quix0rs-gnu-social.git] / actions / editapplication.php
index 9cc3e3cead0cac9670a11f2761d7e0f5d9f11118..477bcd6f0b25b79649b2994310e5237de065ca02 100644 (file)
@@ -179,13 +179,16 @@ class EditApplicationAction extends OwnerDesignAction
         } elseif (mb_strlen($name) > 255) {
             $this->showForm(_('Name is too long (max 255 chars).'));
             return;
+        } else if ($this->nameExists($name)) {
+            $this->showForm(_('Name already in use. Try another one.'));
+            return;
         } elseif (empty($description)) {
             $this->showForm(_('Description is required.'));
             return;
         } elseif (Oauth_application::descriptionTooLong($description)) {
             $this->showForm(sprintf(
                 _('Description is too long (max %d chars).'),
-                                    Oauth_application::maxDescription()));
+                                    Oauth_application::maxDesc()));
             return;
         } elseif (mb_strlen($source_url) > 255) {
             $this->showForm(_('Source URL is too long.'));
@@ -250,7 +253,10 @@ class EditApplicationAction extends OwnerDesignAction
 
         $result = $this->app->update($orig);
 
-        if (!$result) {
+        // Note: 0 means no rows changed, which can happen if the only
+        // thing we changed was the icon, since it's not altered until
+        // the next step.
+        if ($result === false) {
             common_log_db_error($this->app, 'UPDATE', __FILE__);
             $this->serverError(_('Could not update application.'));
         }
@@ -260,5 +266,26 @@ class EditApplicationAction extends OwnerDesignAction
         common_redirect(common_local_url('oauthappssettings'), 303);
     }
 
+    /**
+     * Does the app name already exist?
+     *
+     * Checks the DB to see someone has already registered an app
+     * with the same name.
+     *
+     * @param string $name app name to check
+     *
+     * @return boolean true if the name already exists
+     */
+
+    function nameExists($name)
+    {
+        $newapp = Oauth_application::staticGet('name', $name);
+        if (empty($newapp)) {
+            return false;
+        } else {
+            return $newapp->id != $this->app->id;
+        }
+    }
+
 }