]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile_tag.php
move core schema to class files
[quix0rs-gnu-social.git] / classes / Profile_tag.php
index eb583c98fe06f4f126921631e8c33a48ffa8b110..d9b094182f1dcb7e11b343d0a2f232e00e4fc8d6 100644 (file)
@@ -4,7 +4,7 @@
  */
 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
 
-class Profile_tag extends Memcached_DataObject
+class Profile_tag extends Managed_DataObject
 {
     ###START_AUTOCODE
     /* the code below is auto generated do not remove the above tag */
@@ -22,6 +22,30 @@ class Profile_tag extends Memcached_DataObject
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
+    public static function schemaDef()
+    {
+        return array(
+
+            'fields' => array(
+                'tagger' => array('type' => 'int', 'not null' => true, 'description' => 'user making the tag'),
+                'tagged' => array('type' => 'int', 'not null' => true, 'description' => 'profile tagged'),
+                'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this notice'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date the tag was added'),
+            ),
+            'primary key' => array('tagger', 'tagged', 'tag'),
+            'foreign keys' => array(
+                'profile_tag_tagger_fkey' => array('profile', array('tagger' => 'id')),
+                'profile_tag_tagged_fkey' => array('profile', array('tagged' => 'id')),
+                'profile_tag_tag_fkey' => array('profile_list', array('tag' => 'tag')),
+            ),
+            'indexes' => array(
+                'profile_tag_modified_idx' => array('modified'),
+                'profile_tag_tagger_tag_idx' => array('tagger', 'tag'),
+                'profile_tag_tagged_idx' => array('tagged'),
+            ),
+        );
+    }
+
     function pkeyGet($kv) {
         return Memcached_DataObject::pkeyGet('Profile_tag', $kv);
     }
@@ -143,6 +167,7 @@ class Profile_tag extends Memcached_DataObject
         if (Event::handle('StartTagProfile', array($tagger_profile, $tagged_profile, $tag))) {
 
             if (!$tagger_profile->canTag($tagged_profile)) {
+                // TRANS: Client exception thrown trying to set a tag for a user that cannot be tagged.
                 throw new ClientException(_('You cannot tag this user.'));
                 return false;
             }
@@ -152,6 +177,7 @@ class Profile_tag extends Memcached_DataObject
             $count = (int) $tags->count('distinct tag');
 
             if ($count >= common_config('peopletag', 'maxtags')) {
+                // TRANS: Client exception thrown trying to set more tags than allowed.
                 throw new ClientException(sprintf(_('You already have created %d or more tags ' .
                                                     'which is the maximum allowed number of tags. ' .
                                                     'Try using or deleting some existing tags.'),
@@ -165,9 +191,10 @@ class Profile_tag extends Memcached_DataObject
             $profile_list = Profile_list::ensureTag($tagger, $tag, $desc, $private);
 
             if ($profile_list->taggedCount() >= common_config('peopletag', 'maxpeople')) {
-                throw new ClientException(sprintf(_('You already have %d or more people tagged %s ' .
+                // TRANS: Client exception thrown when trying to add more people than allowed to a list.
+                throw new ClientException(sprintf(_('You already have %1$d or more people in list %2$s, ' .
                                                     'which is the maximum allowed number.' .
-                                                    'Try untagging others with the same tag first.'),
+                                                    'Try unlisting others first.'),
                                                     common_config('peopletag', 'maxpeople'), $tag));
                 return false;
             }
@@ -221,7 +248,9 @@ class Profile_tag extends Memcached_DataObject
             Event::handle('EndUntagProfile', array($orig));
             if ($result) {
                 $profile_list = Profile_list::pkeyGet(array('tag' => $tag, 'tagger' => $tagger));
-                $profile_list->taggedCount(true);
+                if (!empty($profile_list)) {
+                    $profile_list->taggedCount(true);
+                }
                 self::blowCaches($tagger, $tagged);
                 return true;
             }
@@ -286,4 +315,26 @@ class Profile_tag extends Memcached_DataObject
         }
         return true;
     }
+
+    function insert()
+    {
+        $result = parent::insert();
+        if ($result) {
+            self::blow('profile_list:tagged_count:%d:%s', 
+                       $this->tagger,
+                       $this->tag);
+        }
+        return $result;
+    }
+
+    function delete()
+    {
+        $result = parent::delete();
+        if ($result) {
+            self::blow('profile_list:tagged_count:%d:%s', 
+                       $this->tagger,
+                       $this->tag);
+        }
+        return $result;
+    }
 }