コード例 #1
0
 public static function beforeSchemaUpdate()
 {
     $table = strtolower(get_called_class());
     $schema = Schema::get();
     $schemadef = $schema->getTableDef($table);
     // 2016-01-06 We have to make sure there is no conversation with id==0 since it will screw up auto increment resequencing
     if ($schemadef['fields']['id']['auto_increment']) {
         // since we already have auto incrementing ('serial') we can continue
         return;
     }
     // The conversation will be recreated in upgrade.php, which will
     // generate a new URI, but that's collateral damage for you.
     $conv = new Conversation();
     $conv->id = 0;
     if ($conv->find()) {
         while ($conv->fetch()) {
             // Since we have filtered on 0 this only deletes such entries
             // which I have been afraid wouldn't work, but apparently does!
             // (I thought it would act as null or something and find _all_ conversation entries)
             $conv->delete();
         }
     }
 }
コード例 #2
0
ファイル: upgrade.php プロジェクト: bashrc/gnusocial-debian
function fixupConversationURIs()
{
    printfnq("Ensuring all conversations have a URI...");
    $conv = new Conversation();
    $conv->whereAdd('uri IS NULL');
    if ($conv->find()) {
        $rounds = 0;
        while ($conv->fetch()) {
            $uri = common_local_url('conversation', array('id' => $conv->id));
            $sql = sprintf('UPDATE conversation SET uri="%1$s" WHERE id="%2$d";', $conv->escape($uri), $conv->id);
            $conv->query($sql);
            if (($conv->N - ++$rounds) % 500 == 0) {
                printfnq(sprintf(' %d items left...', $conv->N - $rounds));
            }
        }
    }
    printfnq("DONE.\n");
}