{"action":"created","issue":{"url":"https://api.github.com/repos/spatie/laravel-medialibrary/issues/677","repository_url":"https://api.github.com/repos/spatie/laravel-medialibrary","labels_url":"https://api.github.com/repos/spatie/laravel-medialibrary/issues/677/labels{/name}","comments_url":"https://api.github.com/repos/spatie/laravel-medialibrary/issues/677/comments","events_url":"https://api.github.com/repos/spatie/laravel-medialibrary/issues/677/events","html_url":"https://github.com/spatie/laravel-medialibrary/pull/677","id":242827921,"number":677,"title":"Fixed medialibrary:clean command for custom path generators","user":{"login":"ModernArtisan","id":5820718,"avatar_url":"https://avatars1.githubusercontent.com/u/5820718?v=4","gravatar_id":"","url":"https://api.github.com/users/ModernArtisan","html_url":"https://github.com/ModernArtisan","followers_url":"https://api.github.com/users/ModernArtisan/followers","following_url":"https://api.github.com/users/ModernArtisan/following{/other_user}","gists_url":"https://api.github.com/users/ModernArtisan/gists{/gist_id}","starred_url":"https://api.github.com/users/ModernArtisan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ModernArtisan/subscriptions","organizations_url":"https://api.github.com/users/ModernArtisan/orgs","repos_url":"https://api.github.com/users/ModernArtisan/repos","events_url":"https://api.github.com/users/ModernArtisan/events{/privacy}","received_events_url":"https://api.github.com/users/ModernArtisan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-07-13T20:55:30Z","updated_at":"2017-07-19T17:09:13Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/spatie/laravel-medialibrary/pulls/677","html_url":"https://github.com/spatie/laravel-medialibrary/pull/677","diff_url":"https://github.com/spatie/laravel-medialibrary/pull/677.diff","patch_url":"https://github.com/spatie/laravel-medialibrary/pull/677.patch"},"body":"Related to issue #665 \r\nCustom paths can be with any nesting level. After deleting the directory, we should check for parent directories on empty recursively, and if it's empty - remove them too.\r\nThis is also justified for remove a single media model.\r\nI'm tested it with several path generators. For example implementation of **partitioned id** structure:\r\n```php\r\nuse Exception;\r\nuse Spatie\\MediaLibrary\\Media;\r\nuse Spatie\\MediaLibrary\\PathGenerator\\PathGenerator;\r\n\r\nclass MediaPathGenerator implements PathGenerator\r\n{\r\n    /**\r\n     * @param Media $media\r\n     * @return string\r\n     * @throws Exception\r\n     */\r\n    public function getPath(Media $media) : string\r\n    {\r\n        $id = $this->ensurePrintable($media->getKey());\r\n        if (is_numeric($id)) {\r\n            return implode('/', str_split(sprintf('%09d', $id), 3)) . '/';\r\n        } elseif (is_string($id)) {\r\n            return implode('/', array_slice(str_split($id, 3), 0, 3)) . '/';\r\n        }\r\n\r\n        throw new Exception('Unsupported type for generating correct file path storage');\r\n    }\r\n\r\n    /**\r\n     * @param Media $media\r\n     * @return string\r\n     */\r\n    public function getPathForConversions(Media $media) : string\r\n    {\r\n        return $this->getPath($media) . 'conversions/';\r\n    }\r\n\r\n    /**\r\n     * Utility method to ensure the input data only contains\r\n     * printable characters. This is especially important when\r\n     * handling non-printable ID's such as binary UUID's.\r\n     *\r\n     * @param mixed $input\r\n     *\r\n     * @return mixed\r\n     */\r\n    protected function ensurePrintable($input)\r\n    {\r\n        if (! is_numeric($input) && ! ctype_print($input)) {\r\n            // Hash the input data with SHA-256 to represent\r\n            // as printable characters, with minimum chances\r\n            // of the uniqueness being lost.\r\n            return hash('sha256', $input);\r\n        }\r\n\r\n        return $input;\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/spatie/laravel-medialibrary/issues/comments/316453760","html_url":"https://github.com/spatie/laravel-medialibrary/pull/677#issuecomment-316453760","issue_url":"https://api.github.com/repos/spatie/laravel-medialibrary/issues/677","id":316453760,"user":{"login":"ModernArtisan","id":5820718,"avatar_url":"https://avatars1.githubusercontent.com/u/5820718?v=4","gravatar_id":"","url":"https://api.github.com/users/ModernArtisan","html_url":"https://github.com/ModernArtisan","followers_url":"https://api.github.com/users/ModernArtisan/followers","following_url":"https://api.github.com/users/ModernArtisan/following{/other_user}","gists_url":"https://api.github.com/users/ModernArtisan/gists{/gist_id}","starred_url":"https://api.github.com/users/ModernArtisan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ModernArtisan/subscriptions","organizations_url":"https://api.github.com/users/ModernArtisan/orgs","repos_url":"https://api.github.com/users/ModernArtisan/repos","events_url":"https://api.github.com/users/ModernArtisan/events{/privacy}","received_events_url":"https://api.github.com/users/ModernArtisan/received_events","type":"User","site_admin":false},"created_at":"2017-07-19T17:09:13Z","updated_at":"2017-07-19T17:09:13Z","body":"Of course, we can remove this intermediate variables.\r\nThe main goal of my PR - it's to show, how we can resolve current issue.\r\nWhat exactly do you think we need to test?\r\nHow we can avoid the adding a method to an interface in this case?"}}
{"actor":{"display_login":"ModernArtisan"}}