示例#1
0
 /**
  * Get path of file the class is stored in
  *
  * @param	string			$className
  * @param	bool			$relative
  *
  * @return	string
  */
 public static function getClassPath($className, $relative = false)
 {
     $fileName = XDT_CLI_Autoloader::getFileName($className);
     if ($relative) {
         return $fileName;
     }
     return XDT_CLI_Application::xfBaseDir() . 'library' . DIRECTORY_SEPARATOR . $fileName;
 }
示例#2
0
 /**
  * Run the command
  *
  * @param	string			$addonId
  *
  * @return	void
  */
 public function run($addonId)
 {
     // Detect addon
     if (!($addon = $this->getParent()->getAddonById($addonId)) and !($addon = $this->getParent()->getAddonByName($addonId)) and !($addon = $this->getParent()->getAddonByPath($addonId))) {
         $this->bail('Could not find addon: ' . $addonId);
     }
     // Define full file path
     $base = XDT_CLI_Application::xfBaseDir();
     $file = isset($addon['config_file']) ? dirname($addon['config_file']) : '';
     // Validate file path
     if ($this->hasFlag('delete-files') and (empty($file) or !is_dir($base . $file))) {
         $this->bail('Could not locate files');
     }
     // Confirmation
     if (!$this->hasFlag('y')) {
         $this->printMessage('You are about to delete..');
         // Print summary of data that is to be deleted
         if ($this->hasFlag('delete-files')) {
             $files = trim(shell_exec('find ' . $base . $file . ' -type f | wc -l'));
             $folders = trim(shell_exec('find ' . $base . $file . ' -type d | wc -l'));
             $this->printTable(array(array('Addon:', $addon['title'], 'id: ' . $addon['addon_id']), array('Directory:', $file, "{$files} files, {$folders} folders")), '   ', false);
             $this->printEmptyLine();
         } else {
             $this->printEmptyLine();
             $this->printMessage('  Addon: ' . $addon['title'] . ' (' . $addon['addon_id'] . ')');
         }
         // Ask for confirmation
         $this->printEmptyLine();
         $really = $this->confirm('Are you sure you want to do this?');
         $this->printEmptyLine();
         // Fail if not confirmed
         if (!$really) {
             return $this->printMessage('Addon delete canceled');
         }
     }
     // Delete DB data
     $this->printMessage('Deleting DB data.. ', false);
     /** @var XenForo_Model_AddOn $addonModel */
     $addonModel = XenForo_Model::create('XenForo_Model_AddOn');
     $addonModel->deleteAddOnMasterData($addonId);
     $this->printMessage('ok');
     // Delete files
     if ($this->hasFlag('delete-files')) {
         $this->printMessage('Deleting files.. ', false);
         if ($deleted = shell_exec('rm -Rv ' . $base . $file)) {
             $this->printMessage('ok');
         } else {
             $this->bail('failed: ' . $deleted);
         }
     }
     // Done
     $this->printEmptyLine();
     $this->printMessage('Addon delete');
 }
示例#3
0
 /**
  * Get file path for class
  *
  * @param		string		$className
  *
  * @return		string|bool
  */
 public static function getClassPath($className)
 {
     $fileName = self::getFileName($className);
     $dirs = array(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
     if (class_exists('XDT_CLI_Application', false)) {
         $xfBase = XDT_CLI_Application::xfBaseDir();
         array_unshift($dirs, $xfBase . 'library' . DIRECTORY_SEPARATOR);
     }
     foreach ($dirs as $dir) {
         if (file_exists($dir . $fileName)) {
             return $dir . $fileName;
         }
     }
     return false;
 }
示例#4
0
 /**
  * Attempt to retreive addon config file for given addon
  *
  * @param		array|string		$addon
  *
  * @return		bool|string
  */
 public function getAddonConfigFile($addon)
 {
     // Convert string to the array input we're expecting
     if (is_string($addon)) {
         $addon = array('addon_id' => $addon, 'title' => $addon);
     }
     // Validate input
     if (!is_array($addon) or !isset($addon['addon_id'], $addon['title'])) {
         return false;
     }
     // Define the addon folder names we will be checking for
     $names = array($addon['addon_id'], strtolower($addon['addon_id']), XDT_CLI_Helper::camelcaseString($addon['addon_id'], false), XDT_CLI_Helper::camelcaseString($addon['title'], false));
     // If title contains the '-' character, turn it into folder bits
     $bits = explode('-', $addon['title']);
     if (count($bits) > 1) {
         foreach ($bits as &$bit) {
             $bit = XDT_CLI_Helper::camelcaseString($bit, false);
         }
         $names[] = implode('/', $bits);
         $names[] = strtolower(implode('/', $bits));
     }
     // Set variations (with and without library folder)
     $variations = array();
     foreach ($names as $name) {
         $variations = array_merge($variations, array($name, 'library/' . $name));
     }
     // Locate the config file
     $base = XDT_CLI_Application::xfBaseDir();
     return XDT_CLI_Helper::locate('.xfcli-config', $variations, $base, array($base));
 }
示例#5
0
 /**
  * Create files and folders
  * 
  * @param	object			$addon
  * 
  * @return	void							
  */
 protected function createStructure(&$addon)
 {
     $this->printMessage('Creating folder structure.. ', false);
     $base = XDT_CLI_Application::xfBaseDir();
     // Check if path option was given
     if ($this->getOption('path')) {
         $path = $this->getOption('path');
         // Check if path given is absolute or relative, requires that relative paths start alphabetical or with a dot
         if (preg_match('/[a-z.]/i', substr($path, 0, 1))) {
             if (substr($path, 0, 7) != 'library') {
                 $path = 'library' . DIRECTORY_SEPARATOR . $path;
                 // prepend library folder
             }
         }
         $addon->path = $path;
     } else {
         // Otherwise generate the path based on addon id
         $addon->path = 'library' . DIRECTORY_SEPARATOR . ucfirst($addon->id);
     }
     // Strip the base path from the addon path
     if (strpos(realpath($addon->path), realpath($base)) === 0) {
         $addon->path = substr(realpath($addon->path), strlen(realpath($base)) + 1);
     }
     // Check if we need to create the directory
     if (!is_dir($base . $addon->path)) {
         if (!mkdir($base . $addon->path, 0755, true)) {
             $this->bail('Could not locate or create addon directory: ' . $addon->path);
         }
         $this->printMessage('ok');
     } else {
         $this->printMessage('skipped (already exists)');
     }
     // Append directory separator at the end of the path
     if (substr($addon->path, -1) != DIRECTORY_SEPARATOR) {
         $addon->path .= DIRECTORY_SEPARATOR;
     }
     if ($pos = strpos($addon->path, 'library/') !== false) {
         $namespace = substr($addon->path, $pos + 7);
         $namespace = substr($namespace, 0, strlen($namespace) - 1);
         $namespace = str_replace(DIRECTORY_SEPARATOR, '_', $namespace);
         $addon->namespace = $namespace;
     }
 }