mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-22 13:07:59 +01:00
Migrate command
This commit is contained in:
parent
b71efac59f
commit
e6143f7c06
3 changed files with 154 additions and 3 deletions
|
@ -19,6 +19,7 @@ class MigrateOldData extends Command {
|
||||||
$oldDb = DB::connection('old');
|
$oldDb = DB::connection('old');
|
||||||
$oldUsers = $oldDb->table('users')->get();
|
$oldUsers = $oldDb->table('users')->get();
|
||||||
|
|
||||||
|
$this->info('Syncing Users');
|
||||||
foreach ($oldUsers as $user) {
|
foreach ($oldUsers as $user) {
|
||||||
$displayName = $user->display_name;
|
$displayName = $user->display_name;
|
||||||
if (!$displayName)
|
if (!$displayName)
|
||||||
|
@ -44,9 +45,150 @@ class MigrateOldData extends Command {
|
||||||
'can_see_explicit_content' => $user->can_see_explicit_content,
|
'can_see_explicit_content' => $user->can_see_explicit_content,
|
||||||
'mlpforums_name' => $user->mlpforums_name,
|
'mlpforums_name' => $user->mlpforums_name,
|
||||||
'uses_gravatar' => $user->uses_gravatar,
|
'uses_gravatar' => $user->uses_gravatar,
|
||||||
'gravatar' => $user->gravatar
|
'gravatar' => $user->gravatar,
|
||||||
|
'avatar_id' => null
|
||||||
|
]);
|
||||||
|
|
||||||
|
$coverId = null;
|
||||||
|
if (!$user->uses_gravatar) {
|
||||||
|
$coverFile = $this->getIdDirectory('users', $user->id) . '/' . $user->id . '_.png';
|
||||||
|
$coverId = \Entities\Image::upload(new Symfony\Component\HttpFoundation\File\UploadedFile($coverFile, $user->id . '_.png'), $user->id)->id;
|
||||||
|
DB::table('users')->where('id', $user->id)->update(['avatar_id' => $coverId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('Syncing Genres');
|
||||||
|
$oldGenres = $oldDb->table('genres')->get();
|
||||||
|
foreach ($oldGenres as $genre) {
|
||||||
|
DB::table('genres')->insert([
|
||||||
|
'id' => $genre->id,
|
||||||
|
'name' => $genre->title,
|
||||||
|
'slug' => $genre->slug
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->info('Syncing Albums');
|
||||||
|
$oldAlbums = $oldDb->table('albums')->get();
|
||||||
|
foreach ($oldAlbums as $playlist) {
|
||||||
|
DB::table('albums')->insert([
|
||||||
|
'title' => $playlist->title,
|
||||||
|
'description' => $playlist->description,
|
||||||
|
'created_at' => $playlist->created_at,
|
||||||
|
'updated_at' => $playlist->updated_at,
|
||||||
|
'deleted_at' => $playlist->deleted_at,
|
||||||
|
'slug' => $playlist->slug,
|
||||||
|
'id' => $playlist->id,
|
||||||
|
'user_id' => $playlist->user_id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('Syncing Tracks');
|
||||||
|
$oldTracks = $oldDb->table('tracks')->get();
|
||||||
|
foreach ($oldTracks as $track) {
|
||||||
|
$coverId = null;
|
||||||
|
if ($track->cover) {
|
||||||
|
$coverFile = $this->getIdDirectory('tracks', $track->id) . '/' . $track->id . '_' . $track->cover . '.png';
|
||||||
|
$coverId = \Entities\Image::upload(new Symfony\Component\HttpFoundation\File\UploadedFile($coverFile, $track->id . '_' . $track->cover . '.png'), $track->user_id)->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::table('tracks')->insert([
|
||||||
|
'id' => $track->id,
|
||||||
|
'title' => $track->title,
|
||||||
|
'slug' => $track->slug,
|
||||||
|
'description' => $track->description,
|
||||||
|
'lyrics' => $track->lyrics,
|
||||||
|
'created_at' => $track->created_at,
|
||||||
|
'deleted_at' => $track->deleted_at,
|
||||||
|
'updated_at' => $track->updated_at,
|
||||||
|
'released_at' => $track->released_at,
|
||||||
|
'published_at' => $track->published_at,
|
||||||
|
'genre_id' => $track->genre_id,
|
||||||
|
'is_explicit' => $track->explicit,
|
||||||
|
'is_downloadable' => $track->downloadable,
|
||||||
|
'is_vocal' => $track->is_vocal,
|
||||||
|
'track_type_id' => $track->track_type_id,
|
||||||
|
'track_number' => $track->track_number,
|
||||||
|
'user_id' => $track->user_id,
|
||||||
|
'album_id' => $track->album_id,
|
||||||
|
'cover_id' => $coverId,
|
||||||
|
'license_id' => $track->license_id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$oldShowSongs = $oldDb->table('song_track')->get();
|
||||||
|
foreach ($oldShowSongs as $song) {
|
||||||
|
DB::table('show_song_track')->insert([
|
||||||
|
'id' => $song->id,
|
||||||
|
'show_song_id' => $song->song_id,
|
||||||
|
'track_id' => $song->track_id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('Syncing Playlists');
|
||||||
|
$oldPlaylists = $oldDb->table('playlists')->get();
|
||||||
|
foreach ($oldPlaylists as $playlist) {
|
||||||
|
DB::table('playlists')->insert([
|
||||||
|
'title' => $playlist->title,
|
||||||
|
'description' => $playlist->description,
|
||||||
|
'created_at' => $playlist->created_at,
|
||||||
|
'updated_at' => $playlist->updated_at,
|
||||||
|
'deleted_at' => $playlist->deleted_at,
|
||||||
|
'slug' => $playlist->slug,
|
||||||
|
'id' => $playlist->id,
|
||||||
|
'user_id' => $playlist->user_id,
|
||||||
|
'is_pinned' => true,
|
||||||
|
'is_public' => true
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('Syncing Playlist Tracks');
|
||||||
|
$oldPlaylistTracks = $oldDb->table('playlist_tracks');
|
||||||
|
foreach ($oldPlaylistTracks as $playlistTrack) {
|
||||||
|
DB::table('playlist_tracks')->insert([
|
||||||
|
'id' => $playlistTrack['id'],
|
||||||
|
'created_at' => $playlistTrack['created_at'],
|
||||||
|
'updated_at' => $playlistTrack['updated_at'],
|
||||||
|
'position' => $playlistTrack['position'],
|
||||||
|
'playlist_id' => $playlistTrack['playlist_id'],
|
||||||
|
'track_id' => $playlistTrack['track_id']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('Syncing Comments');
|
||||||
|
$oldComments = $oldDb->table('comments');
|
||||||
|
foreach ($oldComments as $fav) {
|
||||||
|
DB::table('comments')->insert([
|
||||||
|
'id' => $fav->id,
|
||||||
|
'user_id' => $fav->user_id,
|
||||||
|
'created_at' => $fav->created_at,
|
||||||
|
'deleted_at' => $fav->deleted_at,
|
||||||
|
'updated_at' => $fav->updated_at,
|
||||||
|
'content' => $fav->content,
|
||||||
|
'track_id' => $fav->track_id,
|
||||||
|
'album_id' => $fav->album_id,
|
||||||
|
'playlist_id' => $fav->playlist_id,
|
||||||
|
'profile_id' => $fav->profile_id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('Syncing Favourites');
|
||||||
|
$oldFavs = $oldDb->table('favourites');
|
||||||
|
foreach ($oldFavs as $fav) {
|
||||||
|
DB::table('favourites')->insert([
|
||||||
|
'id' => $fav->id,
|
||||||
|
'user_id' => $fav->user_id,
|
||||||
|
'created_at' => $fav->created_at,
|
||||||
|
'updated_at' => $fav->updated_at,
|
||||||
|
'track_id' => $fav->track_id,
|
||||||
|
'album_id' => $fav->album_id,
|
||||||
|
'playlist_id' => $fav->playlist_id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getIdDirectory($type, $id) {
|
||||||
|
$dir = (string) ( floor( $id / 100 ) * 100 );
|
||||||
|
return \Config::get('app.files_directory') . '/' . $type . '/' . $dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getArguments()
|
protected function getArguments()
|
||||||
|
|
|
@ -106,6 +106,11 @@ class CreateTracksTable extends Migration {
|
||||||
'title' => 'Ponified Song',
|
'title' => 'Ponified Song',
|
||||||
'editor_title' => 'a non-pony song, turned pony'
|
'editor_title' => 'a non-pony song, turned pony'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
DB::table('track_types')->insert([
|
||||||
|
'title' => 'Official Show Audio Remix',
|
||||||
|
'editor_title' => 'a remix of official show audio'
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function down() {
|
public function down() {
|
||||||
|
|
|
@ -31,15 +31,19 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function upload($file, $user) {
|
public static function upload($file, $user) {
|
||||||
|
$userId = $user;
|
||||||
|
if ($user instanceof User)
|
||||||
|
$userId = $user->id;
|
||||||
|
|
||||||
$hash = md5_file($file->getPathname());
|
$hash = md5_file($file->getPathname());
|
||||||
$image = Image::whereHash($hash)->whereUploadedBy($user->id)->first();
|
$image = Image::whereHash($hash)->whereUploadedBy($userId)->first();
|
||||||
|
|
||||||
if ($image)
|
if ($image)
|
||||||
return $image;
|
return $image;
|
||||||
|
|
||||||
$image = new Image();
|
$image = new Image();
|
||||||
try {
|
try {
|
||||||
$image->uploaded_by = $user->id;
|
$image->uploaded_by = $userId;
|
||||||
$image->size = $file->getSize();
|
$image->size = $file->getSize();
|
||||||
$image->filename = $file->getClientOriginalName();
|
$image->filename = $file->getClientOriginalName();
|
||||||
$image->extension = $file->getClientOriginalExtension();
|
$image->extension = $file->getClientOriginalExtension();
|
||||||
|
|
Loading…
Reference in a new issue