function activate_plugin($plugin)
 {
     if (!AuthUser::hasPermission('administrator')) {
         Flash::set('error', __('You do not have permission to access the requested page!'));
         redirect(get_url());
     }
     Plugin::activate($plugin);
 }
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     \Route::any('plugins', function () {
         \Plugin::activate('clients');
         echo 'hello';
         //print_r(\Plugin::activated());
     });
 }
    $migration->displayWarning("***** Install process of plugin TIMELINETICKET *****");
} else {
    $migration->displayWarning("***** Update process of plugin TIMELINETICKET *****");
}
$migration->displayWarning("Current Timelineticket version: {$current_version}");
$migration->displayWarning("Version to update: " . PLUGIN_TIMELINETICKET_VERSION);
// To prevent problem of execution time
ini_set("max_execution_time", "0");
ini_set("memory_limit", "-1");
$mess = '';
if ($current_version != PLUGIN_TIMELINETICKET_VERSION and $current_version != '0') {
    $mess = "Update done.";
} else {
    if ($current_version == PLUGIN_TIMELINETICKET_VERSION) {
        $mess = "No migration needed.";
    } else {
        $mess = "installation done.";
    }
}
$plugin->getFromDBbyDir("timelineticket");
$plugin->install($plugin->fields['id']);
plugin_timelineticket_install();
$migration->displayWarning($mess);
$plugin->load("timelineticket");
$plugin->activate($plugin->fields['id']);
$plugin->load("timelineticket");
if (in_array('--optimize', $_SERVER['argv'])) {
    $migration->displayTitle("Optimizing tables");
    DBmysql::optimize_tables($migration);
    $migration->displayWarning("Optimize done.");
}
Beispiel #4
0
		$response['error'] = 1;
		$response['message'] = _t('관리자만이 이 기능을 사용할 수 있습니다.');
	} else {
		$response['error'] = 1;

		$pluginName = $_POST['plugin'];
		$ting = (isset($_POST['ting']) && !empty($_POST['ting'])) ? Validator::getBool($_POST['ting']) : null;

		if (!preg_match('/^[A-Za-z0-9 _-]+$/', $pluginName)) {
			$response['message'] = _t('잘못된 플러그인 이름입니다');
			func::printRespond($response);
		}

		if (!is_dir(ROOT . '/plugins/'.$pluginName)) {
			$response['message'] = _t('플러그인이 존재하지 않습니다');
			func::printRespond($response);
		}

		if (!file_exists(ROOT . '/plugins/'.$pluginName.'/index.xml')) {
			$response['message'] = _t('플러그인 정보를 찾을 수 없습니다');
			func::printRespond($response);
		}

		if (Plugin::activate($pluginName, $ting))
			$response['error'] = 0;
	}


	func::printRespond($response);
?>
Beispiel #5
0
 /**
  * Can be used to activate a plugin.
  *
  * @param string $plugin The plugin id.
  */
 public final function activate_plugin($plugin)
 {
     Plugin::activate($plugin);
     Observer::notify('plugin_after_enable', $plugin);
 }
 protected function setUp()
 {
     global $CFG_GLPI, $DB;
     $DB = new DB();
     // Force profile in session to SuperAdmin
     $_SESSION['glpiprofiles'] = array('4' => array('entities' => 0));
     $_SESSION['glpi_plugin_fusioninventory_profile']['unmanaged'] = 'w';
     $_SESSION['glpiactiveentities'] = array(0, 1);
     $_SESSION['glpi_use_mode'] = Session::NORMAL_MODE;
     require GLPI_ROOT . "/inc/includes.php";
     $plugin = new Plugin();
     $DB->connect();
     $plugin->getFromDBbyDir("fusioninventory");
     $plugin->activate($plugin->fields['id']);
     file_put_contents(GLPI_ROOT . "/files/_log/sql-errors.log", '');
     file_put_contents(GLPI_ROOT . "/files/_log/php-errors.log", '');
     $dir = GLPI_ROOT . "/files/_files/_plugins/fusioninventory";
     if (file_exists($dir)) {
         $objects = scandir($dir);
         foreach ($objects as $object) {
             if ($object != "." && $object != "..") {
                 if (filetype($dir . "/" . $object) == "dir") {
                 } else {
                     unlink($dir . "/" . $object);
                 }
             }
         }
     }
     include_once GLPI_ROOT . "/inc/timer.class.php";
     // Security of PHP_SELF
     $_SERVER['PHP_SELF'] = Html::cleanParametersURL($_SERVER['PHP_SELF']);
     //      function glpiautoload($classname) {
     //         global $DEBUG_AUTOLOAD, $CFG_GLPI;
     //         static $notfound = array();
     //
     //         // empty classname or non concerted plugin
     //         if (empty($classname) || is_numeric($classname)) {
     //            return FALSE;
     //         }
     //
     //         $dir=GLPI_ROOT . "/inc/";
     //         //$classname="PluginExampleProfile";
     //         if ($plug=isPluginItemType($classname)) {
     //            $plugname=strtolower($plug['plugin']);
     //            $dir=GLPI_ROOT . "/plugins/$plugname/inc/";
     //            $item=strtolower($plug['class']);
     //            // Is the plugin activate ?
     //            // Command line usage of GLPI : need to do a real check plugin activation
     //            if (isCommandLine()) {
     //               $plugin = new Plugin();
     //               if (count($plugin->find("directory='$plugname' AND state=".Plugin::ACTIVATED)) == 0) {
     //                  // Plugin does not exists or not activated
     //                  return FALSE;
     //               }
     //            } else {
     //               // Standard use of GLPI
     //               if (!in_array($plugname, $_SESSION['glpi_plugins'])) {
     //                  // Plugin not activated
     //                  return FALSE;
     //               }
     //            }
     //         } else {
     //            // Is ezComponent class ?
     //            $matches = array();
     //            if (preg_match('/^ezc([A-Z][a-z]+)/', $classname, $matches)) {
     //               include_once(GLPI_EZC_BASE);
     //               ezcBase::autoload($classname);
     //               return TRUE;
     //            } else {
     //               $item=strtolower($classname);
     //            }
     //         }
     //
     //         // No errors for missing classes due to implementation
     //         if (!isset($CFG_GLPI['missingclasses'])
     //                 OR !in_array($item, $CFG_GLPI['missingclasses'])){
     //            if (file_exists("$dir$item.class.php")) {
     //               include_once ("$dir$item.class.php");
     //               if ($_SESSION['glpi_use_mode']==Session::DEBUG_MODE) {
     //                  $DEBUG_AUTOLOAD[]=$classname;
     //               }
     //
     //            } else if (!isset($notfound["$classname"])) {
     //               // trigger an error to get a backtrace, but only once (use prefix 'x' to handle empty case)
     //               //Toolbox::logInFile('debug', "file $dir$item.class.php not founded trying to load class $classname\n");
     //               trigger_error("GLPI autoload : file $dir$item.class.php not founded trying to load class '$classname'");
     //               $notfound["$classname"] = TRUE;
     //            }
     //         }
     //      }
     //
     //      spl_autoload_register('glpiautoload');
     //      restore_error_handler();
     //      error_reporting(E_ALL | E_STRICT);
     //      ini_set('display_errors', 'On');
     ini_set("memory_limit", "-1");
     ini_set("max_execution_time", "0");
 }
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
namespace dwalkr\WPAdminUtility;

/**
 * psr-4 autoloader
 * http://www.php-fig.org/psr/psr-4/
 */
spl_autoload_register(function ($class) {
    $prefix = __NAMESPACE__;
    $base_dir = dirname(__FILE__) . '/src';
    $len = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) {
        return;
    }
    $relative_class = substr($class, $len);
    $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
    if (file_exists($file)) {
        require $file;
    }
});
register_activation_hook(__FILE__, function () {
    Plugin::activate();
});
add_action('plugins_loaded', function () {
    Plugin::register(plugin_dir_path(__FILE__), plugin_dir_url(__FILE__));
});
 private function manageTicket($closed = true)
 {
     global $DB, $CFG_GLPI;
     $DB->connect();
     $_SESSION['glpiactive_entity'] = 0;
     $CFG_GLPI['root_doc'] = "http://127.0.0.1/fusion0.83/";
     $plugin = new Plugin();
     $plugin->getFromDBbyDir("timelineticket");
     $plugin->activate($plugin->fields['id']);
     Plugin::load("timelineticket");
     Session::loadLanguage("en_GB");
     $ticket = new Ticket();
     $group = new Group();
     $group_ticket = new Group_Ticket();
     $GLPIlog = new GLPIlogs();
     $ticket_User = new Ticket_User();
     $_SESSION['plugin_timelineticket_date'] = array();
     $group->add(array('name' => 'grtech1'));
     $group->add(array('name' => 'grtech2'));
     // * 01/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate = array('1' => $_SESSION["glpi_currenttime"]);
     $input = array();
     $input['name'] = 'Pb with the ticket';
     $input['content'] = 'I have a problem with the ticket';
     $tickets_id = $ticket->add($input);
     $GLPIlog->testSQLlogs('01/');
     $GLPIlog->testPHPlogs('01/');
     // * 02/
     sleep(2);
     // * 03/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[3] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'group';
     $input['_itil_assign']['groups_id'] = 1;
     $ticket->update($input);
     $input['_itil_assign']['_type'] = 'user';
     $input['_itil_assign']['users_id'] = 2;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('03/');
     $GLPIlog->testPHPlogs('03/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $a_ref = array();
     $a_ref[1] = array('id' => '1', 'tickets_id' => '1', 'groups_id' => '1', 'type' => '2');
     $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to group1');
     $a_db = getAllDatasFromTable('glpi_tickets_users');
     $a_ref = array();
     $a_ref[1] = array('id' => '1', 'tickets_id' => '1', 'users_id' => '2', 'type' => '1', 'use_notification' => '1', 'alternative_email' => '');
     $a_ref[2] = array('id' => '2', 'tickets_id' => '1', 'users_id' => '2', 'type' => '2', 'use_notification' => '1', 'alternative_email' => '');
     $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to user 2 (glpi)');
     // * 04/
     sleep(2);
     // * 05/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[5] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['status'] = Ticket::WAITING;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('05/');
     $GLPIlog->testPHPlogs('05/');
     $ticket->getFromDB(1);
     $this->assertEquals('waiting', $ticket->fields['status'], 'May have status waiting');
     // * 06/
     sleep(1);
     // * 07/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[7] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = 2;
     $input['itickets_id'] = $tickets_id;
     $ticket_User->check($input['id'], 'w');
     $ticket_User->delete($input);
     $input = array();
     $input['id'] = 1;
     $input['itickets_id'] = $tickets_id;
     $group_ticket->check($input['id'], 'w');
     $group_ticket->delete($input);
     $GLPIlog->testSQLlogs('07/');
     $GLPIlog->testPHPlogs('07/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $this->assertEquals(array(), $a_db, 'May have no group assigned');
     // * 08/
     sleep(1);
     // * 09/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[9] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'group';
     $input['_itil_assign']['groups_id'] = 2;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('09/');
     $GLPIlog->testPHPlogs('09/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $a_ref = array();
     $a_ref[2] = array('id' => '2', 'tickets_id' => '1', 'groups_id' => '2', 'type' => '2');
     $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to group2');
     $ticket->getFromDB(1);
     $this->assertEquals('assign', $ticket->fields['status'], '(09/) Status is assign');
     // * 10/
     sleep(1);
     // * 11/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[11] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['status'] = Ticket::WAITING;
     $ticket->update($input);
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'user';
     $input['_itil_assign']['users_id'] = 4;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('11/');
     $GLPIlog->testPHPlogs('11/');
     // * 12/
     sleep(1);
     // * 13/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[13] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'group';
     $input['_itil_assign']['groups_id'] = 1;
     $ticket->update($input);
     $input['_itil_assign']['_type'] = 'user';
     $input['_itil_assign']['users_id'] = 2;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('13/');
     $GLPIlog->testPHPlogs('13/');
     $ticket->getFromDB(1);
     $this->assertEquals('waiting', $ticket->fields['status'], '(13/)May have always status waiting');
     // * 14/
     $input = array();
     $input['id'] = 2;
     $input['itickets_id'] = $tickets_id;
     $group_ticket->check($input['id'], 'w');
     $group_ticket->delete($input);
     $GLPIlog->testSQLlogs('14/');
     $GLPIlog->testPHPlogs('14/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $a_ref = array();
     $a_ref[3] = array('id' => '3', 'tickets_id' => '1', 'groups_id' => '1', 'type' => '2');
     $this->assertEquals($a_ref, $a_db, '(14/) May have ticket assigned to group1');
     $ticket->getFromDB(1);
     $this->assertEquals('waiting', $ticket->fields['status'], '(14/) Status is waiting');
     // * 15/
     sleep(2);
     // * 16/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[16] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['status'] = Ticket::ASSIGNED;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('16/');
     $GLPIlog->testPHPlogs('16/');
     // * 17/
     sleep(1);
     // * 18/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[18] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['solution'] = "solution";
     $ticket->update($input);
     $GLPIlog->testSQLlogs('18/');
     $GLPIlog->testPHPlogs('18/');
     $ticket->getFromDB(1);
     $this->assertEquals('solved', $ticket->fields['status'], '(18/) Status is solved');
     if ($closed) {
         // * 19/
         sleep(1);
         // * 20/
         $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
         $a_storedate[20] = $_SESSION["glpi_currenttime"];
         $fup = new TicketFollowup();
         $input = array();
         $input['tickets_id'] = $tickets_id;
         $input['add_close'] = 'add_close';
         $fup->add($input);
         $GLPIlog->testSQLlogs('20/');
         $GLPIlog->testPHPlogs('20/');
         $ticket->getFromDB(1);
         $this->assertEquals('closed', $ticket->fields['status'], '(19/) Status is closed');
     }
     self::$storedate = $a_storedate;
 }