Exemplo n.º 1
0
/**
 * Module is Active Helper
 */
function moduleIsActive($module)
{
    $module = \Developeryamhi\LaravelAdmin\ModuleItem::findModule($module);
    if ($module && $module->isActivated()) {
        return true;
    }
    return false;
}
 /**
  * Load Modules List From Database
  */
 public function loadModulesFromDatabase()
 {
     //	Reset List
     $this->modules = array();
     //	Modules List
     $items = ModuleItem::orderBy("order_index", "ASC")->get();
     //	Process List
     foreach ($items as $item) {
         //  Check if the Path of Module is Valid
         if ($this->app["files"]->exists($item->path)) {
             //	Create Instance
             $module = LaravelModule::createInstance($this->app, $item);
             //  Checkif Module is Fine
             if ($module->isFine()) {
                 //  Store Instance
                 $this->modules[$item->module] = $module;
             }
         }
     }
     //	Sort Modules List
     uasort($this->modules, array($this, 'sort_modules'));
 }
 /**
  * Execute the console command.
  * @return void
  */
 public function fire()
 {
     //	Get Module to Process
     $moduleName = $this->input->getArgument("module");
     //	Get Action to Run
     $action = $this->input->getArgument("action");
     //	Force Action
     $force = $this->option("force") == "true" || $this->option("force") == "1" ? true : false;
     //	Get Module Data
     $moduleFirst = $this->getModule($moduleName);
     //	Check Module Not Found
     if ($moduleName && !$moduleFirst) {
         //	Return Error
         return $this->error("Module [{$moduleName}] is not registered to the system or not available. Please check for the existence");
     }
     //  Modules
     $modules = array();
     if (!$moduleName) {
         $modules = app("laravel-modules")->modules();
     } else {
         $modules = array($moduleFirst);
     }
     //	Return Message
     $returnInfo = true;
     $returnMessages = array();
     //  Loop Each
     foreach ($modules as $module) {
         //	Switch Action
         switch (strtolower($action)) {
             //	Activate
             case 'activate':
                 //	Try the Activation
                 $response = $module->activate($force);
                 //	Check True
                 if ($response === TRUE) {
                     //	Set Message
                     $returnMessages[] = "Module [{$module->name()}] successfully activated";
                 } else {
                     //	Set Error
                     $returnInfo = false;
                     //	Messages
                     $messages = \Developeryamhi\LaravelAdmin\ModuleItem::activationResponseTerminal($module, $response);
                     //	Set Message
                     $returnMessages[] = implode(PHP_EOL, $messages);
                 }
                 break;
                 //	Deactivate
             //	Deactivate
             case 'deactivate':
                 //	Try the Deactivation
                 if ($module->deactivate()) {
                     //	Set Message
                     $returnMessages[] = "Module [{$module->name()}] successfully deactivated.";
                 } else {
                     //  Set Return Info
                     $returnInfo = false;
                     //	Set Message
                     $returnMessages[] = "Module [{$module->name()}] deactivation failed. Module must be locked.";
                 }
                 break;
                 //	Delete
             //	Delete
             case 'delete':
                 //	Try the Delete
                 if ($module->delete()) {
                     //	Set Message
                     $returnMessages[] = "Module [{$module->name()}] successfully deleted from the system.";
                 } else {
                     //  Set Return Info
                     $returnInfo = false;
                     //	Set Message
                     $returnMessages[] = "Module [{$module->name()}] deletion failed. Module must be locked or enabled.";
                 }
                 break;
                 //	Sync
             //	Sync
             case 'sync':
                 //	Try the Sync
                 $module->syncFromMeta();
                 //	Set Message
                 $returnMessages[] = "Module [{$module->name()}] info successfully synced to the system";
                 break;
                 //	Default
             //	Default
             default:
                 return $this->info("Invalid Action [{$action}] requested for module [{$module->name()}].");
                 break;
         }
     }
     //  Check Modules
     if (sizeof($modules) > 0) {
         // Autoload classes
         $this->dumpAutoload();
     } else {
         //	Set Message
         $returnMessages[] = "No modules available in the system to process";
     }
     //	Check Info Message
     if ($returnMessages) {
         if ($returnInfo) {
             return $this->info(implode(PHP_EOL, $returnMessages));
         } else {
             return $this->error(implode(PHP_EOL, $returnMessages));
         }
     }
 }
 /**
  * Load Module Data from Database
  */
 public function loadFromDatabaseObject($obj = null)
 {
     //  Search Object
     $obj || ($obj = ModuleItem::findModule($this->name));
     //  Check
     if ($obj) {
         //	Store Object
         $this->moduleItem = $obj;
         //	Store Details
         $this->moduleName = $obj->name;
         $this->moduleDescription = $obj->description;
         $this->version = $obj->version;
         $this->is_package = (bool) $obj->is_package;
         $this->order = (int) $obj->order_index;
         $this->is_enabled = (bool) $obj->enabled;
         $this->locked = (bool) intval($obj->locked);
         $this->dependsOn = unserialize($obj->depends_on);
         $this->metaData = unserialize($obj->meta_data);
     }
 }
 public function delete_module($id)
 {
     //  Get Module Item
     $moduleItem = ModuleItem::find($id);
     //  Check Module Exists
     if (!$moduleItem) {
         return Redirect::route("modules")->with(FLASH_MSG_ERROR, trans("laravel-admin::message.module_not_found"));
     }
     //  Get Module
     $module = getTheModule($moduleItem->module);
     //  Check Module Exists
     if (!$module) {
         return Redirect::route("modules")->with(FLASH_MSG_ERROR, trans("laravel-admin::message.module_not_found2", array("module" => $moduleItem->module)));
     }
     //  Run Module Delete
     if ($module->delete()) {
         //  Redirect
         return Redirect::route("modules")->with(FLASH_MSG_SUCCESS, trans("laravel-admin::message.module_deleted", array("module" => $module->moduleName())));
     } else {
         //  Redirect
         return Redirect::route("modules")->with(FLASH_MSG_SUCCESS, trans("laravel-admin::message.module_delete_failed", array("module" => $module->moduleName())));
     }
 }