62
FLEXIBLE FILE PATHS FROM THE START Prevent Drupal Headaches Wednesday, January 15, 14

Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

  • View
    4.706

  • Download
    0

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

FLEXIBLE FILE PATHS FROM THE START

Prevent Drupal Headaches

Wednesday, January 15, 14

Page 2: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

training.acquia.com/events

Wednesday, January 15, 14

Page 3: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Who is this for?• New to Drupal?

• Starting a new Drupal site!

• Inherited a new Drupal site and want to know more about configuration

Wednesday, January 15, 14

Page 4: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

In this demo• How file path patterns

affect maintenance and migrations

• File upload management

• Future friendly path patterns

Wednesday, January 15, 14

Page 5: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Source of the pain?• Drupal default file

field upload pops ALL files into the same directory

• Often overlooked by developers

• Significant performance impact

• Easy to prevent!

• ...not easy to fix!

Wednesday, January 15, 14

Page 7: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

https://drupal.org/node/2128055

A future fix

Wednesday, January 15, 14

Page 9: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

A clean room• Protips!• Many potential conflicts with other modules

that control file system. Use clean testing sites.

• See Create a Test Site | Drupal.org

Wednesday, January 15, 14

Page 10: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Out of the box file handling

Getting to grip with the basics

Wednesday, January 15, 14

Page 11: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Basic settings• Global settings• Display options• Upload destination

• Per content type settings• Required?• Help text• Allowed extensions• File directory• Upload size• Description field• Progress indicator• Number of values

Wednesday, January 15, 14

Page 12: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Limiting file types• Security tip: Err on the side of less file

extensions available to the least amount of users

Wednesday, January 15, 14

Page 13: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Description field setting

Wednesday, January 15, 14

Page 14: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

The description

Wednesday, January 15, 14

Page 15: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

CompareWithout “description” With “description”

Wednesday, January 15, 14

Page 16: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

The “display” optionDisplay enabled Display disabled

Wednesday, January 15, 14

Page 17: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Manage field display

Wednesday, January 15, 14

Page 18: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Field report!

Wednesday, January 15, 14

Page 19: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Transliteration• You NEED transliteration. Install it.• Configuration > Media > File system•

Wednesday, January 15, 14

Page 21: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Fix existing file names

Wednesday, January 15, 14

Page 22: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

How many is too many?

Wednesday, January 15, 14

Page 23: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

The extreme limits• FAT32:• Maximum number of files: 268,435,437• Maximum file size: 4GB• maximum number of files per directory: up to 65535, or less depending

on file names• NTFS:• Maximum number of files: 4,294,967,295• Maximum file size: 16TB currently (16EB theoretically)• Ext2:• Maximum number of files: 10¹⁸• Maximum file size: 2TB• theoretical file per directory limit: 1.3 × 10²⁰ files• Ext3:• Maximum number of files: number of bytes in volume/2¹³.• Maximum file size: 16GB (1KB block) to 2TB (4KB block)•http://stackoverflow.com/questions/466521/how-many-

files-in-a-directory-is-too-manyWednesday, January 15, 14

Page 24: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

What’s wrong?• Slow to load directory for maintenance and

migration• Performance hit loading files from that

directory

• Set Max at 1000 or 100,000- well below your “limit”

Wednesday, January 15, 14

Page 25: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

File path patterns

Wednesday, January 15, 14

Page 26: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Configure file paths• Basic settings are

limited

• arbitary text

• entitytype/filetype

• Example: article/pdfs

Wednesday, January 15, 14

Page 27: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

A better idea!• sites/default/files/YYYY/MM/DD• For high volume uploads

https://drupal.org/node/2128055Wednesday, January 15, 14

Page 28: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Token for file directory!• Set to date

Wednesday, January 15, 14

Page 29: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

File (Field) Paths• Set file name also• Node tokens• Transliteration

Wednesday, January 15, 14

Page 30: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Example file path patterns• Parent directory by date• Parent directory by content type• Parent directory by a combination of content

type and author

Wednesday, January 15, 14

Page 31: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Pathauto• Requires Token• Set patterns for paths instead of node/1

Wednesday, January 15, 14

Page 32: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Private and public files

Wednesday, January 15, 14

Page 33: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

public:// & private://• Public

• Anyone can download them

• Private

• Controlling access to the files

Wednesday, January 15, 14

Page 34: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Private• Specify a directory

outside of the doc root folder

Example../private

• OR Sub-directory under the public directory

Examplesites/default/files/private

https://drupal.org/documentation/modules/file

Wednesday, January 15, 14

Page 35: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Private directory• Create the private directory at same level as

root folder• Configuration > Media > File system• Set file system path

• System creates .htaccess file

Wednesday, January 15, 14

Page 37: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Per field options• Select private file

• The paths will be like /system/files/ebooks/pressrelease.pdf

Wednesday, January 15, 14

Page 38: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

What happens?• Field inherits access publishing settings of

content

Wednesday, January 15, 14

Page 40: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

More complex file handling needed?

Wednesday, January 15, 14

Page 41: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

A flexible solution• Media +

• File entity +

• OEmbed +

• CKEditor

• Being used in Drupal Commons and Demo Framework

Wednesday, January 15, 14

Page 42: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Demo Framework• A good example of media configuration• http://drupal.org/project/df

Wednesday, January 15, 14

Page 43: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

CKEditor Link

https://drupal.org/project/ckeditor_link_filehttps://drupal.org/project/ckeditor_link

Wednesday, January 15, 14

Page 45: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Future friendly

Wednesday, January 15, 14

Page 46: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Media module 2.x• Adds an upload widget

Wednesday, January 15, 14

Page 47: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

File entity• File entity (fieldable files)• Add fields to files, group, add display modes,

use Token• Working on getting this into D8

• Documentation at drupal.org/node/1591498

Wednesday, January 15, 14

Page 48: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Fieldable entity

Wednesday, January 15, 14

Page 49: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

File browser• File browser and uploader

Wednesday, January 15, 14

Page 50: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

File settings (global)• Configuration »

Media » File settings

• Global file field settings

Wednesday, January 15, 14

Page 51: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Granular file permissions

Wednesday, January 15, 14

Page 52: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Display formatter

Wednesday, January 15, 14

Page 53: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Further extend• Media module - Handing files from external

sources and services such as YouTube, Vimeo and Flickr.

• File entity revisions module

Wednesday, January 15, 14

Page 55: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Display formatting• Additional display formatters

Wednesday, January 15, 14

Page 56: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Display formatting

Wednesday, January 15, 14

Page 57: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

File view modes

Wednesday, January 15, 14

Page 58: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Fix it? HALP!

Wednesday, January 15, 14

Page 59: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Remediation • Move files to new directories• Recreate all the files using your new tokens• If you embed “inline” files/images, you’d

have to write a script to find and replace.

• Public files are easier.• Drupal handled files are easier.• Example: Media is embedding a file ID.

Wednesday, January 15, 14

Page 60: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Migrate Module• Use Migrate module to do an in-place

migrate of your own site.

drupal.org/project/migrateWednesday, January 15, 14

Page 61: Preventing Drupal Headaches: Establishing Flexible File Paths From The Start

Professional help• Acquia Professional Services• Migration services

Wednesday, January 15, 14