public function handle(InstallThemeCommand $command)
 {
     $theme = new Theme();
     $repository = $this->repositoryFactory->build($command->type, $command->repository);
     if ($command->private and $this->pusher->hasValidLicenseKey()) {
         $repository->makePrivate();
     }
     $repository->setBranch($command->branch);
     $theme->setRepository($repository);
     $theme->setSubdirectory($command->subdirectory);
     $command->dryRun ?: $this->upgrader->installTheme($theme);
     if ($command->subdirectory) {
         $slug = end(explode('/', $command->subdirectory));
     } else {
         $slug = $repository->getSlug();
     }
     $theme = $this->themes->fromSlug($slug);
     $theme->setRepository($repository);
     $theme->setPushToDeploy($command->ptd);
     $theme->setSubdirectory($command->subdirectory);
     $this->themes->store($theme);
     do_action('wppusher_theme_was_installed', new ThemeWasInstalled($theme));
 }
 /**
  * @param $repository
  * @return Theme
  * @throws ThemeNotFound
  */
 public function pusherThemeFromRepository($repository)
 {
     global $wpdb;
     $table_name = pusherTableName();
     $model = new PackageModel(array('repository' => $repository));
     $row = $wpdb->get_row("SELECT * FROM {$table_name} WHERE type = 2 AND repository = '{$model->repository}'");
     if (!$row or !file_exists(get_theme_root() . "/" . $row->package)) {
         throw new ThemeNotFound('Couldn\'t find theme.');
     }
     $object = wp_get_theme($row->package);
     $theme = Theme::fromWpThemeObject($object);
     $repository = $this->repositoryFactory->build($row->host, $row->repository);
     $repository->setBranch($row->branch);
     $theme->setRepository($repository);
     $theme->setPushToDeploy($row->ptd);
     $theme->setHost($row->host);
     $theme->setSubdirectory($row->subdirectory);
     if ($row->private) {
         $theme->repository->makePrivate();
     }
     return $theme;
 }
 /**
  * @param $repository
  * @return Plugin $plugin
  * @throws PluginNotFound
  */
 public function pusherPluginFromRepository($repository)
 {
     include_once ABSPATH . 'wp-admin/includes/plugin.php';
     global $wpdb;
     $table_name = pusherTableName();
     $model = new PackageModel(array('repository' => $repository));
     $row = $wpdb->get_row("SELECT * FROM {$table_name} WHERE type = 1 AND repository = '{$model->repository}'");
     if (!$row or !file_exists(WP_PLUGIN_DIR . "/" . $row->package)) {
         throw new PluginNotFound('Could not find plugin.');
     }
     $array = get_plugin_data(WP_PLUGIN_DIR . "/" . $row->package);
     $plugin = Plugin::fromWpArray($row->package, $array);
     $repository = $this->repositoryFactory->build($row->host, $row->repository);
     $repository->setBranch($row->branch);
     $plugin->setRepository($repository);
     $plugin->setPushToDeploy($row->ptd);
     $plugin->setHost($row->host);
     $plugin->setSubdirectory($row->subdirectory);
     if ($row->private) {
         $plugin->repository->makePrivate();
     }
     return $plugin;
 }