Merge pull request #1036 from openclassify/vedat

fixed seeder
This commit is contained in:
Dia Shalabi 2021-04-16 11:13:32 +03:00 committed by GitHub
commit b53a852a6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 162 additions and 143 deletions

View File

@ -64,4 +64,9 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
{ {
$this->update(['icon' => $url]); $this->update(['icon' => $url]);
} }
public function getSubCategories()
{
return $this->where('parent_category_id', $this->getId())->get();
}
} }

View File

@ -146,13 +146,13 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
'c1.id', 'c1.id',
'c1.slug', 'c1.slug',
'c1.parent_category_id', 'c1.parent_category_id',
'c1.icon_id', 'c1.icon',
't1.name', 't1.name',
'c2.id as c2_id', 'c2.id as c2_id',
'c2.slug as c2_slug', 'c2.slug as c2_slug',
'c2.icon as c2_icon',
'c2.parent_category_id as c2_parent_category_id', 'c2.parent_category_id as c2_parent_category_id',
't2.name as c2_name', 't2.name as c2_name'
'file.id as file_id'
) )
->leftJoin($dBName . ' as c2', function ($join) { ->leftJoin($dBName . ' as c2', function ($join) {
$join->on('c2.parent_category_id', '=', 'c1.id') $join->on('c2.parent_category_id', '=', 'c1.id')
@ -166,7 +166,6 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
$join->on('c2.id', '=', 't2.entry_id') $join->on('c2.id', '=', 't2.entry_id')
->where('t2.locale', Request()->session()->get('_locale', setting_value('streams::default_locale'))); ->where('t2.locale', Request()->session()->get('_locale', setting_value('streams::default_locale')));
}) })
->leftJoin('files_files as file', 'c1.icon_id', 'file.id')
->whereNull('c1.deleted_at') ->whereNull('c1.deleted_at')
->whereNull('c1.parent_category_id') ->whereNull('c1.parent_category_id')
->orderBy('c1.sort_order') ->orderBy('c1.sort_order')

View File

@ -13,4 +13,6 @@ interface CategoryInterface extends EntryInterface
public function getMains($id); public function getMains($id);
public function setCategoryIconUrl($url); public function setCategoryIconUrl($url);
public function getSubCategories();
} }

View File

@ -6,158 +6,165 @@ use Anomaly\FilesModule\Folder\Contract\FolderRepositoryInterface;
use Anomaly\NavigationModule\Link\LinkModel; use Anomaly\NavigationModule\Link\LinkModel;
use Anomaly\NavigationModule\Menu\Contract\MenuRepositoryInterface; use Anomaly\NavigationModule\Menu\Contract\MenuRepositoryInterface;
use Anomaly\Streams\Platform\Entry\EntryRepository; use Anomaly\Streams\Platform\Entry\EntryRepository;
use Anomaly\Streams\Platform\Model\Users\UsersUsersEntryModel;
use Anomaly\UrlLinkTypeExtension\UrlLinkTypeModel; use Anomaly\UrlLinkTypeExtension\UrlLinkTypeModel;
use Anomaly\UsersModule\Role\Contract\RoleRepositoryInterface; use Anomaly\UsersModule\Role\Contract\RoleRepositoryInterface;
use Anomaly\UsersModule\User\Contract\UserInterface;
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface; use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
use Anomaly\UsersModule\User\UserActivator; use Anomaly\UsersModule\User\UserActivator;
use Illuminate\Console\Command;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Anomaly\DashboardModule\Widget\Contract\WidgetRepositoryInterface; use Anomaly\DashboardModule\Widget\Contract\WidgetRepositoryInterface;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use WidgetSeeder;
use ZipArchive;
class DatabaseSeeder extends Seeder class DatabaseSeeder extends Seeder
{ {
protected $widgets; protected $widgets;
protected $menus; protected $menus;
protected $users; protected $users;
protected $roles; protected $roles;
protected $activator; protected $activator;
protected $disks; protected $disks;
protected $folders; protected $folders;
protected $command;
public function __construct( public function __construct(
WidgetRepositoryInterface $widgets, WidgetRepositoryInterface $widgets,
MenuRepositoryInterface $menus, MenuRepositoryInterface $menus,
UserRepositoryInterface $users, UserRepositoryInterface $users,
DiskRepositoryInterface $disks, DiskRepositoryInterface $disks,
FolderRepositoryInterface $folders, FolderRepositoryInterface $folders,
RoleRepositoryInterface $roles, RoleRepositoryInterface $roles,
UserActivator $activator UserActivator $activator,
) Command $command
{ )
$this->widgets = $widgets; {
$this->menus = $menus; $this->widgets = $widgets;
$this->users = $users; $this->menus = $menus;
$this->roles = $roles; $this->users = $users;
$this->activator = $activator; $this->roles = $roles;
$this->disks = $disks; $this->activator = $activator;
$this->folders = $folders; $this->disks = $disks;
} $this->folders = $folders;
$this->command = $command;
}
public function run() public function run()
{ {
$admin = $this->roles->findBySlug('admin'); $admin = $this->roles->findBySlug('admin');
$this->users->unguard(); $this->users->unguard();
$this->users->newQuery()->where('email', "info@openclassify.com")->forceDelete(); $this->users->newQuery()->where('email', "info@openclassify.com")->forceDelete();
$visiosoft_administrator = $this->users->create( $visiosoft_administrator = $this->users->create(
[ [
'first_name' => 'Dev', 'first_name' => 'Dev',
'last_name' => 'Openclassify', 'last_name' => 'Openclassify',
'display_name' => 'openclassify', 'display_name' => 'openclassify',
'email' => "info@openclassify.com", 'email' => "info@openclassify.com",
'username' => "openclassify", 'username' => "openclassify",
'password' => "openclassify", 'password' => "openclassify",
] ]
); );
$visiosoft_administrator->roles()->sync([$admin->getId()]); $visiosoft_administrator->roles()->sync([$admin->getId()]);
$this->activator->force($visiosoft_administrator); $this->activator->force($visiosoft_administrator);
//Footer Link //Footer Link
LinkModel::query()->forceDelete(); LinkModel::query()->forceDelete();
$repository = new EntryRepository(); $repository = new EntryRepository();
$repository->setModel(new UrlLinkTypeModel()); $repository->setModel(new UrlLinkTypeModel());
$menu = $this->menus->findBySlug('footer'); $menu = $this->menus->findBySlug('footer');
$openclassify = $repository->create( $openclassify = $repository->create(
[ [
'en' => [ 'en' => [
'title' => 'OpenClassify.com', 'title' => 'OpenClassify.com',
], ],
'url' => 'https://openclassify.com/', 'url' => 'https://openclassify.com/',
] ]
); );
$visiosoft = $repository->create( $visiosoft = $repository->create(
[ [
'en' => [ 'en' => [
'title' => 'Visiosoft Inc.', 'title' => 'Visiosoft Inc.',
], ],
'url' => 'https://visiosoft.com.tr/', 'url' => 'https://visiosoft.com.tr/',
] ]
); );
LinkModel::query()->create( LinkModel::query()->create(
[ [
'menu' => $menu, 'menu' => $menu,
'target' => '_blank', 'target' => '_blank',
'entry' => $openclassify, 'entry' => $openclassify,
'type' => 'anomaly.extension.url_link_type', 'type' => 'anomaly.extension.url_link_type',
] ]
); );
LinkModel::query()->create( LinkModel::query()->create(
[ [
'menu' => $menu, 'menu' => $menu,
'target' => '_blank', 'target' => '_blank',
'entry' => $visiosoft, 'entry' => $visiosoft,
'type' => 'anomaly.extension.url_link_type', 'type' => 'anomaly.extension.url_link_type',
] ]
); );
$repository = "https://raw.githubusercontent.com/openclassify/Openclassify-Demo-Data/upgrade3.8/"; $repository = "https://raw.githubusercontent.com/openclassify/Openclassify-Demo-Data/master/";
file_put_contents(storage_path('advs.sql'), fopen($repository . "advs.sql", 'r')); file_put_contents(storage_path('advs.sql'), fopen($repository . "advs.sql", 'r'));
file_put_contents(storage_path('settings.sql'), fopen($repository . "settings.sql", 'r')); file_put_contents(storage_path('settings.sql'), fopen($repository . "settings.sql", 'r'));
file_put_contents(storage_path('categories.sql'), fopen($repository . "categories.sql", 'r')); file_put_contents(storage_path('categories.sql'), fopen($repository . "categories.sql", 'r'));
file_put_contents(storage_path('images.zip'), fopen($repository . "images.zip", "r")); file_put_contents(storage_path('images.zip'), fopen($repository . "images.zip", "r"));
file_put_contents(storage_path('cats.zip'), fopen($repository . "cats.zip", "r")); file_put_contents(storage_path('cats.zip'), fopen($repository . "cats.zip", "r"));
Model::unguard(); Model::unguard();
DB::unprepared(file_get_contents(storage_path('advs.sql'))); DB::unprepared(file_get_contents(storage_path('advs.sql')));
DB::unprepared(file_get_contents(storage_path('categories.sql'))); DB::unprepared(file_get_contents(storage_path('categories.sql')));
DB::unprepared(file_get_contents(storage_path('settings.sql'))); DB::unprepared(file_get_contents(storage_path('settings.sql')));
Model::reguard(); Model::reguard();
$zip = new ZipArchive(); $zip = new \ZipArchive();
$zip->open(storage_path('images.zip'), ZipArchive::CREATE); $zip->open(storage_path('images.zip'), ZipArchive::CREATE);
$zip->extractTo(storage_path('streams/default/files-module/local/images/')); $zip->extractTo(storage_path('streams/default/files-module/local/images/'));
$zip->open(storage_path('cats.zip'), ZipArchive::CREATE); $zip->open(storage_path('cats.zip'), ZipArchive::CREATE);
$zip->extractTo(storage_path('streams/default/files-module/local/images/')); $zip->extractTo(storage_path('streams/default/files-module/local/category_icon/'));
$zip->close(); $zip->close();
$this->call(widgetSeeder::class); //Sync Files
$this->command->call('files:sync');
$this->call(WidgetSeeder::class);
//Create Store Icon Folder //Create Store Icon Folder
if (!$this->folders->findBySlug('ads_excel')) { if (!$this->folders->findBySlug('ads_excel')) {
$disk = $this->disks->findBySlug('local'); $disk = $this->disks->findBySlug('local');
$this->folders->create([ $this->folders->create([
'en' => [ 'en' => [
'name' => 'Ads Excel', 'name' => 'Ads Excel',
'description' => 'A folder for Ads Excel.', 'description' => 'A folder for Ads Excel.',
], ],
'slug' => 'ads_excel', 'slug' => 'ads_excel',
'disk' => $disk 'disk' => $disk
]); ]);
}; };
if ($images_folder = $this->folders->findBySlug('images')) { if ($images_folder = $this->folders->findBySlug('images')) {
$images_folder->update([ $images_folder->update([
'allowed_types' => [ 'allowed_types' => [
'jpg', 'jpeg','png' 'jpg', 'jpeg', 'png'
], ],
]); ]);
} }
//Favicon Folder //Favicon Folder
@ -165,35 +172,35 @@ class DatabaseSeeder extends Seeder
$disk = $this->disks->findBySlug('local'); $disk = $this->disks->findBySlug('local');
$this->folders->create([ $this->folders->create([
'en' => [ 'en' => [
'name' => 'Favicon', 'name' => 'Favicon',
'description' => 'A folder for Favicon.', 'description' => 'A folder for Favicon.',
], ],
'slug' => 'favicon', 'slug' => 'favicon',
'disk' => $disk, 'disk' => $disk,
'allowed_types' => [ 'allowed_types' => [
'ico','png', 'ico', 'png',
], ],
]); ]);
}; };
//Create Ads Documents Folder //Create Ads Documents Folder
if (!$this->folders->findBySlug('ads_documents')) { if (!$this->folders->findBySlug('ads_documents')) {
$disk = $this->disks->findBySlug('local'); $disk = $this->disks->findBySlug('local');
$this->folders->create([ $this->folders->create([
'en' => [ 'en' => [
'name' => 'Ads Documents', 'name' => 'Ads Documents',
'description' => 'A folder for Ads Documents.', 'description' => 'A folder for Ads Documents.',
], ],
'slug' => 'ads_documents', 'slug' => 'ads_documents',
'disk' => $disk, 'disk' => $disk,
'allowed_types' => [ 'allowed_types' => [
'pdf', 'doc', 'docx', 'xls', 'xlsx', 'pdf', 'doc', 'docx', 'xls', 'xlsx',
], ],
]); ]);
}; };
//Create Category Icon Folder //Create Category Icon Folder
@ -210,6 +217,12 @@ class DatabaseSeeder extends Seeder
]); ]);
}; };
//Demodata Seeder
if(is_module_installed('visiosoft.module.demodata'))
{
$this->call(\Visiosoft\DemodataModule\Demodata\DemodataSeeder::class);
}
Artisan::call('assets:clear'); Artisan::call('assets:clear');
} }
} }

View File

@ -5,7 +5,7 @@ use Anomaly\DashboardModule\Dashboard\Contract\DashboardRepositoryInterface;
use Anomaly\DashboardModule\Widget\Contract\WidgetRepositoryInterface; use Anomaly\DashboardModule\Widget\Contract\WidgetRepositoryInterface;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
class widgetSeeder extends Seeder class WidgetSeeder extends Seeder
{ {
protected $widgets; protected $widgets;
protected $dashboards; protected $dashboards;